Displaying a second window in Qt and sending a signal back

16 views Asked by At

When launching a class the second window has no contents:

    QWidget* w = new demo2();
    w->show();

The target has:

    demo2::demo2()
    {
     QVBoxLayout* layout = new QVBoxLayout;
     button2 = new QPushButton( "demo2" );
     layout->addWidget(button2);
   
     //connect( button2, SIGNAL( clicked() ), demo1, SLOT( fromDemo2() ) );
The button does not show up but a blank window does.
If the connect instruction is uncommented the compiler
complains about demo1 "error: expected primary-expression before ‘,’"



I tried several variations, but could not get it to work.
2

There are 2 answers

0
Bruce Dubbs On

Solved. To get the display I needed to add setLayout(layout); in demo2.cpp.

To solve the connect issue I had to turn it around so when class demo2 is instantiated in demo1.cpp:

demo2* w = new demo2();
connect( w->button2, SIGNAL(clicked() ), this, SLOT( fromDemo2() ) );
w->show();
0
Noushadali On

I think you are missing setting the layout part. See the example on the Qt Documentation.