0

我一直在寻找有关此问题的信息..但我找到的解决方案都没有帮助我,我真的希望你能帮助我

  • 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;
    }
    
  • 主.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
    

编译器错误是:

    [...]\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

你能帮忙吗?我会很感激...

4

2 回答 2

3

您正在使用由uicQt 生成的文件;您应该验证此工具是否成功生成文件,例如检查构建输出和文件本身。此外,检查它是否在*.pro文件中(即,maintabholder.h标记为由 处理uic)。

我个人建议对 ui使用多重继承方法:

// in maintabholder.h
// ...
#include "ui_maintabholder.h"

class MainTabHolder : public QMainWindow, public Ui::MainTabHolder
{
    // ...
};

使用更简单,如果ui_*.h文件有问题,错误会更明确。

你应该发帖ui_maintabholder.h

于 2013-02-20T15:37:10.170 回答
0

您在 .cpp 文件中包含了 ui 定义头,并定义了一个私有成员“Ui::MainTabHolder *ui;” 在你的 .h 文件中,所以你需要在你的类定义之前在你的 .h 文件(maintabholder.h:) 中添加一个前向声明:

class Ui_MainTabHolder;

这里 Ui_MainTabHolder 是你的 Ui 类名,检查你自己的项目是否正确。

于 2013-03-15T09:50:47.100 回答