Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Display traffic light example on a newly created Mainwindow Gui.
Forum Updated to NodeBB v4.3 + New Features

Display traffic light example on a newly created Mainwindow Gui.

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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 ?

      157

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

        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()
        @

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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.

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved