I have a strange problem. I've built an application in a QMainWindow class. But now I need to rebuild it into something that will share the main window with others. So I've built a new QMainWindow class that will house everything. window.h file:
#ifndef WINDOW_H
#define WINDOW_H
#include <QMainWindow>
#include "widget.h"
namespace Ui {
class window;
}
{
Q_OBJECT
public:
explicit window
(QWidget *parent
= 0);
~window();
private:
Ui::window *ui;
};
#endif // WINDOW_H
#ifndef WINDOW_H
#define WINDOW_H
#include <QMainWindow>
#include "widget.h"
namespace Ui {
class window;
}
class window : public QMainWindow
{
Q_OBJECT
public:
explicit window(QWidget *parent = 0);
~window();
private:
Ui::window *ui;
};
#endif // WINDOW_H
To copy to clipboard, switch view to plain text mode
And then I've tried to rewrite the old main windows as a QWidget and have the window show it. widget.h file:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class widget;
}
{
Q_OBJECT
public:
explicit widget
(QWidget *parent
= 0);
~widget();
private:
Ui::widget *ui;
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class widget;
}
class widget : public QWidget
{
Q_OBJECT
public:
explicit widget(QWidget *parent = 0);
~widget();
private:
Ui::widget *ui;
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
This the code I use minus the internal methods. And the compilation error is on first line of the widget constructor:
widget::widget(QWidget *parent) : QWidget(parent), ui(new Ui::widget)
To copy to clipboard, switch view to plain text mode
Which says "invalid use of incomplete type 'struct Ui::widget'".
Now, I've tried looking it up and I've found that this kind of error usually occurs through recursive definitions and integrations where by the time the compiler is doing the line in error, it needs definitions that won't become available until later on or even inside the class.
Following the instructions on building an example, I did manage to write pretty much the same thing from scratch with, as far as I can see, the same code as the one I pasted and it works perfectly.
So, my question is, did anyone already try doing what I did and can tell me what I'm doing wrong or any suggestions on how I can do it without writing the whole thing from scratch? Because right now it seems like I have to and I'd like to avoid it.
Proper notice: I am a newbie to Qt and am still using a lot of automatics like the Designer, the automatic slot connection and the likes...
Bookmarks