crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

> Передача данных
Dimix
  опции профиля:
сообщение 14.2.2011, 3:38
Сообщение #1


Студент
*

Группа: Участник
Сообщений: 74
Регистрация: 24.11.2010
Пользователь №: 2215

Спасибо сказали: 0 раз(а)




Репутация:   0  


Немогу спокойно спать. Хочу понять как передавать данные.
Создал пустой проэкт Qt datastream
Раскрывающийся текст
HEADERS += \
mainwindow.h \
dialog.h

SOURCES += \
mainwindow.cpp \
dialog.cpp \
main.cpp

FORMS += \
mainwindow.ui \
dialog.ui

Создал 2 класса форм Qt Designer
DIALOG
Раскрывающийся текст
#ifndef DIALOG_H
#define DIALOG_H#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
Q_OBJECT

public:
explicit Dialog(QWidget *parent = 0);
~Dialog();

private:
Ui::Dialog *ui;
};

#endif // DIALOG_H
Раскрывающийся текст
#include "dialog.h"
#include "ui_dialog.h"

#include "mainwindow.h"
#include "ui_mainwindow.h"

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);

MainWindow* main = new MainWindow;

ui->listWidget->addItem(main->ui->lineEdit->text());
ui->listWidget->addItem(main->ui->comboBox->currentText());
}

Dialog::~Dialog()
{
delete ui;
}
Раскрывающийся текст
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>282</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>261</width>
<height>192</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Back</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>200</x>
<y>250</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>110</x>
<y>20</y>
<width>61</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Return label</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

MAINWINDOW
Раскрывающийся текст
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();


Ui::MainWindow *ui;

private slots:
void on_pushButton_clicked();
};

#endif // MAINWINDOW_H
Раскрывающийся текст
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "dialog.h"
#include "ui_dialog.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{
Dialog* dialog = new Dialog;
dialog->show();
return ui->lineEdit->text();
this->close();
}
Раскрывающийся текст
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>142</width>
<height>155</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>111</width>
<height>22</height>
</rect>
</property>
<item>
<property name="text">
<string>Clear</string>
</property>
</item>
<item>
<property name="text">
<string>Dimix</string>
</property>
</item>
<item>
<property name="text">
<string>Shket</string>
</property>
</item>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>80</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Send</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>142</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

И создал файл исходных текстов main
Раскрывающийся текст
#include "mainwindow.h"
#include "ui_mainwindow.h"

int main(int argc, char** argv)
{
QApplication app(argc, argv);

MainWindow* main = new MainWindow;
main->show();

return app.exec();
}

Хочу предать текст из comboBox и lineEdit другой форме на listWidget получаю пустые значения.
Как правильно?

Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Сообщений в этой теме


Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 25.4.2024, 22:48