Invalid use of incomplete type (but I include the header file (?))
-
Hi! The problematic pieces of code seem to be this:
ui_createnode.h:
#ifndef UI_CREATENODE_H #define UI_CREATENODE_H #include <QDialog> namespace Ui { class Ui_createNode; } class Ui_createNode : public QDialog { Q_OBJECT public: explicit Ui_createNode(QWidget *parent = nullptr); ~Ui_createNode(); private: Ui::Ui_createNode *ui; }; #endif // UI_CREATENODE_H
ui_createnode.cpp:
#include "ui_createnode.h" Ui_createNode::Ui_createNode(QWidget *parent) : QDialog(parent), ui(new Ui::Ui_createNode) { ui->setupUi(this); } Ui_createNode::~Ui_createNode() { delete ui; }
The error I get is:
invalid use of incomplete type 'class Ui::Ui_createNode'
ui(new Ui::Ui_createNode)
^~~~~~~~~~~~~But I did include the header file so what's wrong?
Kind regards -
@fT3g0 Do a complete rebuild: delete build folder, run qmake and build.
One moment: why do you have Ui::Ui_createNode *ui inside Ui::Ui_createNode?!
ui classes are used in "normal" classes. So, you should have a class called createNode where you put Ui::Ui_createNode *ui; -
The entire project is somewhat bigger.
What I want to do is to show a dialog when executing a function which is member of a different class, with custom UI.
I created ui_createnode.h, /-.cpp, /-.ui by adding a designer form class.
in net.cpp (not the entire file):
void Net::createNode() { QDialog *dialog_createNode = new QDialog; Ui_createNode *ui_createNode; dialog_createNode->setupUi(ui_createNode); // ERROR: no member named setupUi in QDialog; how do I add the UI to the dialog? dialog_createNode->show(); // more stuff here }
-
@fT3g0 said in Invalid use of incomplete type (but I include the header file (?)):
how do I add the UI to the dialog?
The way you do it in your first post. QDialog doesn't have a member setupUi() but the generated Ui class has.
-
I still haven't managed to solve the problem (sorry for being a noob xD)....
I tried to create the designer form class from scratch and named it "createNodeForm" so I don't have an "ui_" in front which could be confusing.
createnodeform.h
#ifndef CREATENODEFORM_H #define CREATENODEFORM_H #include <QDialog> namespace Ui { class createNodeForm; } class createNodeForm : public QDialog { Q_OBJECT public: explicit createNodeForm(QWidget *parent = nullptr); ~createNodeForm(); private: Ui::createNodeForm *ui; }; #endif // CREATENODEFORM_H
createnodeform.cpp
#include "createnodeform.h" #include "ui_createnodeform.h" createNodeForm::createNodeForm(QWidget *parent) : QDialog(parent), ui(new Ui::createNodeForm) //ERROR: invalid use of incomplete type class "Ui::createNodeForm" { ui->setupUi(this); } createNodeForm::~createNodeForm() { delete ui; }
net.cpp
#include "net.h" #include "mainwindow.h" #include "createnodeform.h" #include "ui_createnodeform.h" // other includes // other functions void Net::createNode() { QDialog *dialog_createNode = new QDialog; createNodeForm *ui_createNode = new createNodeForm; //need to setup the UI and connect it to the dialog, what to do here? dialog_createNode->show(); //other stuff inside the function }
So there is the "incomplete type" error and I haven't managed to connect the UI to the dialog yet.
Also I'm confused what ui_createnodeform.h is about... Is it an automatically generated file (as opposed to createnodeform.h, which I can see and edit)? What is in it and why do I need it?
Also this seems kind of convoluted, having 3 files for every little dialog with custom UI. Is there a simpler way or does one just keep it tidy by using directories at some point?
Kind regards
-
@fT3g0
I'm afraid I know nothing about Qt Designer and its code. Hope I am not actually confusing you. But for:ui(new Ui::createNodeForm) //ERROR: invalid use of incomplete type class "Ui::createNodeForm"
In your header file you have:
namespace Ui { class createNodeForm; } class createNodeForm : public QDialog { ...
The first bit declares that there is a class
createNodeForm
in namespaceUi
, i.e. theUi::createNodeForm
. It does not define that class. The second bit defines a classcreateNodeForm
, but that isn't in namespaceUi
. I don't know, but is yourcreateNodeForm
supposed to be in inside thenamespace Ui
?And I don't know why you seem to want to create a generic
QDialog
separately from yourcreateNodeForm
, which is aQDialog
itself. You're only supposed to create your form-dialog.... -
@fT3g0 said in Invalid use of incomplete type (but I include the header file (?)):
ui_createnodeform.h
Please take a look into this file and make sure there is only one version of it available. Also simply try to remove it to make sure it's the correct one - it is created again by uic.
-
@Christian-Ehrlicher
So is my guess about the namespace declaration in C++ wrong, and I should delete my post as it's incorrect/unhelpful? -
@fT3g0 could it be possible that you start from scratch? :-)
I mean, it seems from the files and filenames you posted that you're kind of misusing the capabilities of Designer and uic tool.
If you create a simple project in Qt Creator, or a form class with Designer, you'll see that 3 files are created (let's say it's a dialog named MyClass):
- myclass.ui
- myclass.h
- myclass.cpp
you see that there's no ui_myclass.h file (yet...)
The idea is that you edit the form graphically with Designer (adding other widgets, buttons, labels, etc. to the dialog) and then you provide your dialog class implementation with the .h/.cpp (mainly the .cpp file).
The ui_myclass.h file will be created at compile time by the uic tool and it'll serve as a bridge between the GUI you designed and any implementation code you may need to better suit your class.
See more about using Designer and .ui files here.