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. Problem with using QHBoxLayout
Forum Updated to NodeBB v4.3 + New Features

Problem with using QHBoxLayout

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 3 Posters 5.8k Views 2 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.
  • W Offline
    W Offline
    Waxta
    wrote on last edited by Waxta
    #1

    Hello.
    I have dumb problem with QHBoxLayout. In constructor of my class I want to create an instance of this class, but compiler shows me a problem in line where I intend to create object: "Use of undefined type QHBoxLayout". Of course I included QHBoxLayout lib above, but compiler still shows me the error. How to fix it?```

    #include <QHBoxLayout>

    IEEEField::IEEEField(QWidget *parent) : QWidget(parent)
    {
    QHBoxLayout * layout = new QHBoxLayout();

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What do you mean by "How to fix it" including QHBoxLayout is the right thing to do. The compiler can create stuff it doesn't know about.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Waxta
        wrote on last edited by Waxta
        #3

        I mean how to make my code works :) I think I did everything correct but compiler gives me errors (I recognize that it's compiler error since error code beginning in C#### e.g C2027). I can give u more code if it's neccesary.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What are the errors you are getting ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Waxta
            wrote on last edited by
            #5

            "use of undefined type QHBoxLayout"

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Well, the fix is to add #include <QHBoxLayout> in the file where you are using QHBoxLayout.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • W Offline
                W Offline
                Waxta
                wrote on last edited by
                #7

                Lawl, look at my first post :D I've done it already.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You wrote Of course I included QHBoxLayout lib above, and there compiler does not show me error.

                  So there's something really not clear about your situation.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    Waxta
                    wrote on last edited by
                    #9

                    ohhh, sorry :D propably I wanted to say something else, don't remember what :D Well, when I include QHBoxLayout it still does not work :/ What's the problem?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Do you have QT += widgets in your .pro file ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        Waxta
                        wrote on last edited by
                        #11

                        Yep, I Have```
                        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          The exact same error even when adding the include ? Where exactly are you adding it ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • W Offline
                            W Offline
                            Waxta
                            wrote on last edited by Waxta
                            #13

                            Yep, same error when adding. I add this file where I use it... if u mean that. :D!!![alt text]Screen(http://ifotos.pl/zobacz/errorzjpg_awhnwxr.jpg) of my other errors in compiler. These errors are in lines where I try to call foncions or do something with layouts.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Show the code you are using, there's something else that's wrong.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • W Offline
                                W Offline
                                Waxta
                                wrote on last edited by Waxta
                                #15

                                One of the file when I try to initiate HBoxLayout. Errors occur when I do something with layout var:

                                #include "ieeefield.h"
                                #include <QLineEdit>
                                #include "qbinaryvalidator.h"
                                #include <QHBoxLayout>
                                
                                IEEEField::IEEEField(QWidget *parent) : QWidget(parent)
                                {
                                    QHBoxLayout * layout = new QHBoxLayout();
                                    QLineEdit * signField = new QLineEdit();
                                    QLineEdit * exponentField = new QLineEdit();
                                    QLineEdit * mantissField = new QLineEdit();
                                
                                    signField->setAlignment(Qt::AlignCenter);
                                    exponentField->setAlignment(Qt::AlignCenter);
                                    mantissField->setAlignment(Qt::AlignCenter);
                                
                                    signField->setMaxLength(1);
                                    exponentField->setMaxLength(8);
                                    mantissField->setMaxLength(23);
                                
                                    QBinaryValidator * binaryValidator = new QBinaryValidator();
                                    signField->setValidator(binaryValidator);
                                    exponentField->setValidator(binaryValidator);
                                    mantissField->setValidator(binaryValidator);
                                    delete binaryValidator;
                                
                                    QFont font;
                                    font.setPointSize(font.pointSize() + 8);
                                    signField->setFont(font);
                                    exponentField->setFont(font);
                                    mantissField->setFont(font);
                                
                                    layout->addWidget(signField);
                                    layout->addWidget(exponentField);
                                    layout->addWidget(mantissField);
                                    delete signField;
                                    delete exponentField;
                                    delete mantissField;
                                
                                    layout->setSpacing(5);
                                    this->setLayout(layout);
                                }
                                
                                1 Reply Last reply
                                0
                                • W Offline
                                  W Offline
                                  Waxta
                                  wrote on last edited by
                                  #16

                                  U know guys, even the calculator example does not work (but I ran this example before and it worked) :D This must be an IDE fault. Any idea?

                                  mrjjM 1 Reply Last reply
                                  0
                                  • W Waxta

                                    U know guys, even the calculator example does not work (but I ran this example before and it worked) :D This must be an IDE fault. Any idea?

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @Waxta
                                    Try to make a default GUI project and see if that works. Maybe add widget and layout to UI.

                                    1 Reply Last reply
                                    0
                                    • W Offline
                                      W Offline
                                      Waxta
                                      wrote on last edited by Waxta
                                      #18

                                      https://doc.qt.io/qt-5/qtwidgets-widgets-calculator-example.html
                                      I copied whole app but still having same problems (mainly with QGridLayout).

                                      Edit: When i double-clicked on random error it reffered me to QHBoxLayout class declaration ![alt text] (http://ifotos.pl/zobacz/errorjpg_awhwxah.jpg)

                                      mrjjM 1 Reply Last reply
                                      0
                                      • W Waxta

                                        https://doc.qt.io/qt-5/qtwidgets-widgets-calculator-example.html
                                        I copied whole app but still having same problems (mainly with QGridLayout).

                                        Edit: When i double-clicked on random error it reffered me to QHBoxLayout class declaration ![alt text] (http://ifotos.pl/zobacz/errorjpg_awhwxah.jpg)

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @Waxta
                                        It seems to be inside Qt files?
                                        Well testing with default project could also be interesting.

                                        1 Reply Last reply
                                        0
                                        • W Offline
                                          W Offline
                                          Waxta
                                          wrote on last edited by
                                          #20

                                          I don't know. I just think the problem will be the same in other projects. The error started appear when I clicked "clear" in procject menu - actually don't know what this option clears XD

                                          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