我一直在寻找有关这个问题的信息。。但我找到的解决方案都没有帮助我,我真的希望你能帮助我
-
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_维护文件夹.h#ifndef UI_MAINTABHOLDER_H#定义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
编译器错误为:
[...]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
你能帮忙吗?我很感激…
您使用的是uic
从Qt生成的文件;您应该通过检查构建输出和文件本身来验证该工具是否成功生成了文件。此外,检查它是否在*.pro
文件中(即maintabholder.h
标记为由uic
处理)。
我个人建议对ui使用多重继承方法:
// in maintabholder.h
// ...
#include "ui_maintabholder.h"
class MainTabHolder : public QMainWindow, public Ui::MainTabHolder
{
// ...
};
使用起来更简单,如果ui_*.h
文件有问题,则错误会更明确。
您应该发布ui_maintabholder.h
您在.cpp文件中包含了ui定义头,并在.h文件中定义了一个私有成员"ui::MainTabHolder*ui;",因此您需要在类定义之前在.h文件(MainTabHolder.h:)中添加一个前向声明:
class Ui_MainTabHolder;
这里的Ui_MainTabHolder是你的Ui类名,请检查你自己的项目是否正确。