Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] opening a widget with qml file included
QtWS25 Last Chance

[solved] opening a widget with qml file included

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 2.4k Views
  • 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.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    @
    prima::prima(QWidget *parent) :
    QWidget(parent)
    {
    QDeclarativeView *primaSchermata = new QDeclarativeView(this);
    primaSchermata->setSource(QUrl::fromLocalFile("qml/OpenOrario/main.qml"));
    primaSchermata->show();

    QObject *obj = primaSchermata->rootObject();
    
    move(0,0);
    showMaximized();
    
    QObject::connect(obj, SIGNAL(signal_nuovoClicked()), this, SLOT(nuovo()));
    

    }

    void prima::nuovo()
    {
    seconda s;
    }
    @

    @
    seconda::seconda(QWidget *parent) :
    QWidget(parent)
    {
    QDeclarativeView *secondaview = new QDeclarativeView(this);
    secondaview->setSource(QUrl::fromLocalFile("qml/OpenOrario/seconda.qml"));
    secondaview->show();

    move(0,0);
    showMaximized();
    

    }
    @

    the second window appears and desappears in a moment...

    [edit : typo fixed in title, Eddy]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      When you enter the prima::nuovo() method, the seconda object gets instantiated on the stack and displayed. As the prima::nuovo() method exits, the seconda object s goes out of scope and the object gets destroyed.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on last edited by
        #3

        0k, so should i use a while, a goto or?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Make your "seconda" instance variable a member of your prima class and use new to create your seconda instance. This is pretty basic C++ stuff.

          @
          class prima ...
          {
          ...
          private:
          seconda *m_seconda;
          }

          void prima::nuovo()
          {
          m_seconda = new seconda(this); // create it on the heap, so it doesn't go out of scope
          }
          @

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            spode
            wrote on last edited by
            #5

            @
            void prima::nuovo()
            {
            seconda s;
            s.show();
            close();
            here:
            goto here;
            }
            @

            the window stops working...

            1 Reply Last reply
            0
            • S Offline
              S Offline
              spode
              wrote on last edited by
              #6

              true. thank you!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                [quote author="spode" date="1317321543"]@
                void prima::nuovo()
                {
                seconda s;
                s.show();
                close();
                here:
                goto here;
                }
                @

                the window stops working...[/quote]

                Oh, that's just so wrong in so many ways... see above.

                But let's step through the code...

                @
                seconda s; // This creates the object
                s.show(); // This shows it. It DOES NOT BLOCK AND WAIT FOR THE WIDGET TO CLOSE
                close(); // This closes the window immediately.
                @

                Here's an exercise. What do you think the
                @
                here:
                goto here;
                @
                code does? (Hint... tight, infinite loop)

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                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