Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QT5: Promoting widget inside a promoted form class
QtWS25 Last Chance

[SOLVED] QT5: Promoting widget inside a promoted form class

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 5.8k 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.
  • J Offline
    J Offline
    Jufa
    wrote on last edited by
    #1

    Hello there!

    I have a MainWindow form. I put a widget inside it and promote it to my class 1. But my class 1 has a form that contains a widget promoted to my class 2. When I try to compile, it gave me the following error:

    @form1.obj:-1: error: LNK2001: unresolved external symbol "public: __thiscall Form2::Form2(class QWidget *)" (??0Form2@@QAE@PAVQWidget@@@Z)@

    What could I do to accomplise this? Is this impossible?

    Thanks you for your answers and time.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      Have you created .h and .cpp files for Form2 class? Are they defined and declared correctly? Linker can't find declaration of constructor function of class Form2. Maybe you have declared your constructor like: Form2() instead of Form2(class QWidget *)?

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jufa
        wrote on last edited by
        #3

        Yes, it's all ok.

        form1.h
        @#ifndef FORM1_H
        #define FORM1_H

        #include <QWidget>

        namespace Ui {
        class Form1;
        }

        class Form1 : public QWidget
        {
        Q_OBJECT

        public:
        explicit Form1(QWidget *parent = 0);
        ~Form1();

        private:
        Ui::Form1 *ui;
        };

        #endif // FORM1_H
        @

        form2.h
        @#ifndef FORM2_H
        #define FORM2_H

        #include <QWidget>

        namespace Ui {
        class Form2;
        }

        class Form2 : public QWidget
        {
        Q_OBJECT

        public:
        explicit Form2(QWidget *parent = 0);
        ~Form2();

        private:
        Ui::Form2 *ui;
        };

        #endif // FORM2_H
        @

        MainWindows contains a widget. This widget is promoted to Form1, wich contains a widget promoted to Form2.

        What should I check now?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on last edited by
          #4

          Which IDE & compiler do you use? I have same construction(promoted widget in promoted widget) and it works in VS(msvc) & QtCreator(gcc). But your linker somhow can't find object file with Form2... Try to include Form2 header in Form1 header to ensure it will be compiled....

          God is Real unless explicitly declared as Integer.

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

            Can you attach an image of the Object Inspector/Explorer of the MainWindow .

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jufa
              wrote on last edited by
              #6

              AcerExtensa, I have VS & QTCreator(vc). I have tried including form2.h in form1.h, but the same result.

              Sam, this is the image:
              "https://docs.google.com/file/d/0B0QWPtcmBoNIRDBmM1p0QVBPOVU/edit":https://docs.google.com/file/d/0B0QWPtcmBoNIRDBmM1p0QVBPOVU/edit

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sam
                wrote on last edited by
                #7

                Nops not this image . open mainwindow.ui the object inspector is on extreme right just above the property explorer.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jufa
                  wrote on last edited by
                  #8

                  Oh, sorry. This one:
                  "https://docs.google.com/file/d/0B0QWPtcmBoNIOWdJOE1XakUyNEE/edit":https://docs.google.com/file/d/0B0QWPtcmBoNIOWdJOE1XakUyNEE/edit

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AcerExtensa
                    wrote on last edited by
                    #9

                    Here is project with promoted widget in promoted widget of main widget. It works in QtCreator(gcc) and in MSVC: "PromoWidget.tar.gz":http://xplatforms.de/PromoWidget.tar.gz

                    Test it in your Environment.

                    God is Real unless explicitly declared as Integer.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Jufa
                      wrote on last edited by
                      #10

                      I'll get crazy with this. Your project works perfect! I have been comparing file by file and all seems exactly the same. But mine keeps giving me this error.

                      This is my project (ultra basic, just like yours):
                      "https://docs.google.com/file/d/0B0QWPtcmBoNIdHFxZ1dHSVpTX0U/edit":https://docs.google.com/file/d/0B0QWPtcmBoNIdHFxZ1dHSVpTX0U/edit

                      Thanks for all your responses and your time!

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        sidewinder
                        wrote on last edited by
                        #11

                        I can compile and run your project without problems whatsoever. Have you tried cleaning your project and rerunning qmake? Sometimes hitting rebuild isn't enough.

                        "Never memorize what you can look up in books."
                        Albert Einstein

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          Jufa
                          wrote on last edited by
                          #12

                          I don't know what you mean with "clean" but I have deleted the debug folder and recompile... and it worked! Thanks everyone! I'll change the post to "solved"!

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            Sam
                            wrote on last edited by
                            #13

                            [quote author="Jufa" date="1359527268"]I don't know what you mean with "clean" [/quote]
                            Right Click on your Project Tree there is an option in the context Menu "Clean" , which will clear the moc files generated by the compiler in debug and release folder of your project.

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              Jufa
                              wrote on last edited by
                              #14

                              Thanks! That made the trick!

                              thread marked as solved.

                              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