msmihai
6th December 2008, 11:27
Hello everybody . I'm new to this forum ( because it's the first time for me using QT but i'm pretty sure i'll be using it regularly from now ) . I followed a couple of tutorials, wrote some simple GUI applications but I could'nt find an answer for my problem .
I have to ui's ( dlg1.ui and dlg2.ui ). dlg1.ui is the main window of my application(project type: MainWindow) , with the name Form1 , and dlg2.ui is another window( project type Widget ) .
Here is how my projects files look like .
main.cpp
#include <qapplication>
#include "app.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
App1 dialog;
dialog.show();
return app.exec();
}
app.h
#ifndef APP_H
#define APP_H
#include "ui_dlg1.h"
#include "ui_dlg2.h"
class App1:public QMainWindow,private Ui::Form1
{
Q_OBJECT
public:
App1();
public slots:
void button_clicked();
};
class App2:public QWidget,private Ui::Form2
{
Q_OBJECT
public:
App2(QWidget *parent = 0);
};
#endif
app.cpp
#include <QtGui>
#include "app.h"
App1::App1()
{
setupUi(this);
connect(pushButton,SIGNAL(clicked()),this,SLOT(but ton_clicked()));
}
App2::App2(QWidget *parent)
{
setupUi(this);
}
void App1::button_clicked()
{
App2 form2(this);
form2.show();
}
This code works just fine but when I press the button , Form2 appears for a very very short time and then it's being destroyed . Why this happens ? And how can I correct it so that Form2 shows as a modal window ( no interraction with Form1 being possible till Form2 is being closed ) .
Furthermore, how can I make two forms communicate with each other ? My idea was a global variabiles in app.cpp that each form can see .
I hope I was clear enough . Have a great day !
I have to ui's ( dlg1.ui and dlg2.ui ). dlg1.ui is the main window of my application(project type: MainWindow) , with the name Form1 , and dlg2.ui is another window( project type Widget ) .
Here is how my projects files look like .
main.cpp
#include <qapplication>
#include "app.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
App1 dialog;
dialog.show();
return app.exec();
}
app.h
#ifndef APP_H
#define APP_H
#include "ui_dlg1.h"
#include "ui_dlg2.h"
class App1:public QMainWindow,private Ui::Form1
{
Q_OBJECT
public:
App1();
public slots:
void button_clicked();
};
class App2:public QWidget,private Ui::Form2
{
Q_OBJECT
public:
App2(QWidget *parent = 0);
};
#endif
app.cpp
#include <QtGui>
#include "app.h"
App1::App1()
{
setupUi(this);
connect(pushButton,SIGNAL(clicked()),this,SLOT(but ton_clicked()));
}
App2::App2(QWidget *parent)
{
setupUi(this);
}
void App1::button_clicked()
{
App2 form2(this);
form2.show();
}
This code works just fine but when I press the button , Form2 appears for a very very short time and then it's being destroyed . Why this happens ? And how can I correct it so that Form2 shows as a modal window ( no interraction with Form1 being possible till Form2 is being closed ) .
Furthermore, how can I make two forms communicate with each other ? My idea was a global variabiles in app.cpp that each form can see .
I hope I was clear enough . Have a great day !