Reputation: 513
I've been looking for info about this problem .. but none of the solutions I've found have helped me, I really hope that you can helpme
maintabholder.h:
#ifndef MAINTABHOLDER_H
#define MAINTABHOLDER_H
#include <QMainWindow>
namespace Ui {
class MainTabHolder;
}
class MainTabHolder : public QMainWindow
{
Q_OBJECT
public:
explicit MainTabHolder(QWidget *parent = 0);
~MainTabHolder();
private:
Ui::MainTabHolder *ui;
};
#endif // MAINTABHOLDER_H
maintabholder.cpp:
#include "maintabholder.h"
#include "ui_maintabholder.h"
MainTabHolder::MainTabHolder(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainTabHolder)
{
ui->setupUi(this);
}
MainTabHolder::~MainTabHolder()
{
delete ui;
}
main.cpp:
#include "maintabholder.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainTabHolder w;
w.show();
return a.exec();
}
ui_maintabholder.h #ifndef UI_MAINTABHOLDER_H #define UI_MAINTABHOLDER_H
#include <QtCore/QVariant>
#include <QtWebKitWidgets/QWebView>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
QHBoxLayout *horizontalLayout;
QTabWidget *tabWidget;
QWidget *comicViewer;
QWidget *comicSearcher;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout_2;
QPushButton *pushButton;
QSpacerItem *horizontalSpacer;
QPushButton *pushButton_2;
QWebView *webView;
void setupUi(QWidget *Form)
{
if (Form->objectName().isEmpty())
Form->setObjectName(QStringLiteral("Form"));
Form->resize(531, 308);
horizontalLayout = new QHBoxLayout(Form);
horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
tabWidget = new QTabWidget(Form);
tabWidget->setObjectName(QStringLiteral("tabWidget"));
comicViewer = new QWidget();
comicViewer->setObjectName(QStringLiteral("comicViewer"));
comicViewer->setCursor(QCursor(Qt::ArrowCursor));
tabWidget->addTab(comicViewer, QString());
comicSearcher = new QWidget();
comicSearcher->setObjectName(QStringLiteral("comicSearcher"));
verticalLayout = new QVBoxLayout(comicSearcher);
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
pushButton = new QPushButton(comicSearcher);
pushButton->setObjectName(QStringLiteral("pushButton"));
horizontalLayout_2->addWidget(pushButton);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer);
pushButton_2 = new QPushButton(comicSearcher);
pushButton_2->setObjectName(QStringLiteral("pushButton_2"));
pushButton_2->setEnabled(false);
horizontalLayout_2->addWidget(pushButton_2);
verticalLayout->addLayout(horizontalLayout_2);
webView = new QWebView(comicSearcher);
webView->setObjectName(QStringLiteral("webView"));
webView->setUrl(QUrl(QStringLiteral("about:blank")));
verticalLayout->addWidget(webView);
tabWidget->addTab(comicSearcher, QString());
horizontalLayout->addWidget(tabWidget);
retranslateUi(Form);
tabWidget->setCurrentIndex(1);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
Form->setWindowTitle(QApplication::translate("Form", "Form", 0));
tabWidget->setTabText(tabWidget->indexOf(comicViewer), QApplication::translate("Form", "Comic Viewer", 0));
pushButton->setText(QApplication::translate("Form", "Go to SubManga", 0));
pushButton_2->setText(QApplication::translate("Form", "Download Comic", 0));
tabWidget->setTabText(tabWidget->indexOf(comicSearcher), QApplication::translate("Form", "Search For Comics", 0));
} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINTABHOLDER_H
the compiler errors are:
[...]\maintabholder.cpp: In constructor 'MainTabHolder::MainTabHolder(QWidget*)':
[...]\maintabholder.cpp:6:16: error: invalid use of incomplete type 'class Ui::MainTabHolder'
In file included from [...]\maintabholder.cpp:1:0:
[...]\maintabholder.h:7:7: error: forward declaration of 'class Ui::MainTabHolder'
[...]\maintabholder.cpp:8:7: error: invalid use of incomplete type 'class Ui::MainTabHolder'
In file included from [...]\maintabholder.cpp:1:0:
[...]\maintabholder.h:7:7: error: forward declaration of 'class Ui::MainTabHolder'
[...]\maintabholder.cpp: In destructor 'virtual MainTabHolder::~MainTabHolder()':
[...]\maintabholder.cpp:13:12: warning: possible problem detected in invocation of delete operator: [enabled by default]
[...]\maintabholder.cpp:13:12: warning: invalid use of incomplete type 'class Ui::MainTabHolder' [enabled by default]
In file included from [...]\maintabholder.cpp:1:0:
[...]\maintabholder.h:7:7: warning: forward declaration of 'class Ui::MainTabHolder' [enabled by default]
[...]\maintabholder.cpp:13:12: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
Can you give a help with this? I would appreciate it...
Upvotes: 0
Views: 5056
Reputation: 9
You included the ui define head in your .cpp file, and defined a private member "Ui::MainTabHolder *ui;" in your .h file, so you need to add a forward declaration in your .h file(maintabholder.h:) before your class defination:
class Ui_MainTabHolder;
here Ui_MainTabHolder is your Ui class name, check your own project for correct one.
Upvotes: 0
Reputation: 9388
You are using a file generated by uic
from Qt; you should verify that this tool successfully generate the file, by for example checking the build output and the file itself. Also, check that it is in the *.pro
file (ie, that maintabholder.h
is marked to be processed by uic
).
I personnally advise to use the multiple inheritance method for ui :
// in maintabholder.h
// ...
#include "ui_maintabholder.h"
class MainTabHolder : public QMainWindow, public Ui::MainTabHolder
{
// ...
};
Simpler to use, and if you have a problem with the ui_*.h
file the error is more explicit.
You should post ui_maintabholder.h
.
Upvotes: 3