Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] opening a widget with qml file included

    QML and Qt Quick
    2
    7
    2079
    Loading More Posts
    • 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
      spode last edited by

      @
      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 Reply Quote 0
      • M
        mlong last edited by

        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 Reply Quote 0
        • S
          spode last edited by

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

          1 Reply Last reply Reply Quote 0
          • M
            mlong last edited by

            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 Reply Quote 0
            • S
              spode last edited by

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

              the window stops working...

              1 Reply Last reply Reply Quote 0
              • S
                spode last edited by

                true. thank you!

                1 Reply Last reply Reply Quote 0
                • M
                  mlong last edited by

                  [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 Reply Quote 0
                  • First post
                    Last post