Display traffic light example on a newly created Mainwindow Gui.
-
I saw the 'Traffic Light Example' in the link below
http://qt-project.org/doc/qt-5/qtwidgets-statemachine-trafficlight-example.html
i would like to display traffic light example on a newly created Mainwindow Gui.can someone advice the trick to do it.
-
Hi,
Wouldn't it be as easy as keeping the 3 classes in a Cpp file and then including it and creating the TrafficLight object as shown in the main ?
-
class Lightwidget, class TrafficLightWidget, class CreateLightState is currently in main.cpp.
I try transfer the 3 class into mainwindow.cpp.
i leave the main.cpp as it is.
@
int main(int argc, char **argv)
{
QApplication app(argc, argv);MainWindow w; w.show(); return app.exec();
}
@
But I put the 3 lines inside mainwindow constructor.
@
TrafficLight widget;
widget.resize(110, 300);
widget.show()
@ -
Since you are creating the object on stack it will get destroyed when the constructor ends. Create it on heap using new operator and pass the mainwindow object as parent to it.