在 Qt 中显示第二个窗口并发送回信号

问题描述 投票:0回答:1

启动课程时,第二个窗口没有内容:

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

目标有:

    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.
qt-signals
1个回答
0
投票

解决了。为了获得显示,我需要添加 setLayout(layout);在demo2.cpp中。

为了解决连接问题,我必须扭转它,因此当在 demo1.cpp 中实例化类 demo2 时:

demo2* w = new demo2();
connect( w->button2, SIGNAL(clicked() ), this, SLOT( fromDemo2() ) );
w->show();
© www.soinside.com 2019 - 2024. All rights reserved.