Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
Quoted
make the QtextEdit item public
Quoted
create a friend class for the second window with the first.
Quoted
let window 1 be parent to window 2 and post items from window 2 to the parent
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#include <QObject>
#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QWidget>
#include <QDialog>
#include <QTextEdit>
class MainWindow : public QWidget
{
Q_OBJECT
public:
QTextEdit *textEdit;
MainWindow( QWidget *parent = 0 );
public slots:
void setTextInMainWindow();
};
MainWindow::MainWindow( QWidget *parent):QWidget( parent )
{
textEdit = new QTextEdit(this);
//QDialog *dialog = new QDialog( 0 );
}
void MainWindow::setTextInMainWindow()
{
//MainWindow tempWin;
textEdit->setPlainText("My Text");
qWarning( "My Text" );
}
class MyDialog : public QDialog
{
Q_OBJECT
public:
QPushButton *pb;
MyDialog( QWidget *parent = 0 );
//public slots:
// void setTextInMainWindow( const QString );
};
MyDialog::MyDialog( QWidget *parent):QDialog( parent )
{
pb = new QPushButton("&Click", this);
//QDialog *dialog = new QDialog( 0 );
}
#include "Hello.moc"
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
MainWindow tempWindow;
MyDialog dialog;
QObject::connect( dialog.pb, SIGNAL( clicked()), &tempWindow, SLOT( setTextInMainWindow() ) ) ;
dialog.show();
tempWindow.show();
return app.exec();
}
|