Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Multiple Widgets

    General and Desktop
    5
    7
    2160
    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.
    • Z
      zEp0 last edited by

      Hello everyone,

      my Problem: I have two Widgets in my Projekt. How can I tell QT, which one he should run at first?

      Thank you!

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        To vague to answer with certainty. Are those 2 QMainWindows? Is one of them a dialog, message box or else?

        In general, in your main routine (int main()), you can show the first widget first, and then when it finishes (you can destroy it, or just hide) you can show the other one. There are also other ways to do it, but I can't really say anything more concrete before you give more details on your situation.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • Z
          zEp0 last edited by

          Thank you for your answer!

          Both Widgets are normal QWidgets..
          I don't know, how I could explain them more precise. I just created a Project with a normal QWidget and then I added the other Widget.

          Thank you!

          1 Reply Last reply Reply Quote 0
          • Q
            qxoz last edited by

            If you create project by QtCreator wizzard so look at main.cpp file:
            @#include <QtGui/QApplication>
            #include "widget.h"

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            Widget w;
            w.show();

            return a.exec&#40;&#41;;
            

            }@
            in line 7 creation of Widget object and at line 8 its shows. Other widget you can show from this one.
            But if you tell as what you try to do then you can get more useful answer.

            1 Reply Last reply Reply Quote 0
            • U
              utcenter last edited by

              [quote author="zEp0" date="1360512318"] How can I tell QT, which one he should run at first?
              Thank you![/quote]

              It will be the one instantiated in your main() function. Widgets are like nesting dolls, you can put widgets inside widgets. So if your second widget needs to show from the first widget, all you need to do is put it in there, just like you would but a button, a check box or any other widget derived component. You can of course always show the second widget conditionally.

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

                It's not the best solution but it is one, because I don't know your exact usage of your application.

                Make your both QWidgets to QDialog (.i.e: "class A : public QWidget" to "class A : public QDialog" ) and then use the exec() function instead of show().
                Like:

                [code]int main(int argc, char *argv[])
                {
                QApplication a(argc, argv);
                WDialog1 w1;
                w1.exec();
                WDialog2 w2;
                w2.exec();

                return a.exec&#40;&#41;;
                

                }[/code]

                It will first start the w1 instance and when you close it, it will start the next instance (w2).

                1 Reply Last reply Reply Quote 0
                • Z
                  zEp0 last edited by

                  Thank you guys, I will try it!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post