[Qt-creator] How to make the QWidgets Window to wait for signal (buttonClick).

Robert Löhning robert.loehning at nokia.com
Fri Feb 26 13:20:43 CET 2010


ext Arun schrieb:
> Hello List,
> I have created a small GUI using two ui files.
> The first UI file has a button and after buttonClickHandler executed it loads the 2nd GUI as defined in an .ui file.
> But, the 2nd Widget does not stay and disaapears immediately.
> 
> void MainWindow::buttonClickHandler()
> {
>   QMessageBox msgBox;
>   msgBox.setWindowTitle("MyWorld");
>   msgBox.setText("Interface for new widgets");
>   msgBox.setInformativeText("Instead of MessageBox, another widget to be shown here");
> 
>    AddressBook addrBook;
>    addrBook.show();
> 
> }
> 
> The above program is fine.
> and the 2nd Widget as :
> 
> --------------------------------
>     #include "addressbook.h"
>     #include <QMessageBox>
>     #include "ui_AddressBook.h"
> 
>     AddressBook::AddressBook(QWidget *parent)
>         : QWidget(parent), ui(new Ui::AddressBookClass)
>     {
>         ui->setupUi(this);
>                                                   (at  this point if I add      "this.show()". It shows both widget at start of the main.
>     }
> 
>     void AddressBook::infoButtonHandler()
>     {
>       QMessageBox msgBox;
>       msgBox.setWindowTitle("MyInfo");
>       msgBox.setText("Details here");
>       msgBox.setInformativeText("Place Holder for My Info");
> 
>        msgBox.exec();
>     }
>     AddressBook::~AddressBook()
>     {
>         delete ui;
>     }
> 
> =============================
> 
> 
> Please reply how the 2nd window shall wait  till the button is clicked.
> 
> 
> Thanks in advance,
> arun
> 
> 
> 
> 

Hi Arun,

this is not a question about Qt Creator, but about Qt itself. Next time, 
you can try asking on the Qt-interest list:

http://lists.trolltech.com/mailman/listinfo/qt-interest

Or on the #qt channel on irc.freenode.net.

I didn't try it but it looks like addrBook is destroyed as it goes out 
of scope. Mind that show() returns immediately. Try making addrBook a 
member of MainWindow class.

Regards,
Robert

-- 
Robert Löhning
Software Engineer
Nokia, Qt Development Frameworks



More information about the Qt-creator-old mailing list