启动课程时,第二个窗口没有内容:
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.
解决了。为了获得显示,我需要添加 setLayout(layout);在demo2.cpp中。
为了解决连接问题,我必须扭转它,因此当在 demo1.cpp 中实例化类 demo2 时:
demo2* w = new demo2();
connect( w->button2, SIGNAL(clicked() ), this, SLOT( fromDemo2() ) );
w->show();