Problem with using QHBoxLayout
-
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(); -
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.
-
What are the errors you are getting ?
-
Well, the fix is to add
#include <QHBoxLayout>
in the file where you are using QHBoxLayout. -
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.
-
Do you have
QT += widgets
in your .pro file ? -
The exact same error even when adding the include ? Where exactly are you adding it ?
-
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.
-
Show the code you are using, there's something else that's wrong.
-
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); }
-
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)