QTProject Meta对象编译器会干扰

发布于 2025-02-08 13:36:49 字数 16238 浏览 1 评论 0原文

我试图为我的地下城爬行者游戏添加图形UI进行大学作业。
这是我第一次使用QT(第一次在这里问一个问题,很抱歉,如果它不连贯,我会很乐意接受建议)
两天以来,我试图将STH与Qdialog,Qmainwindow和一个管理QOBject类一起放在一起。在我之间使用同学的代码,时间压力和从那里开始的启动器中的启动时间变成了一团糟。
我真的不知道如何解释错误消息。因此,我希望这里有人可以同时拥有这些错误消息指示以及如何摆脱这种情况。
我的代码没有错误消息。我怀疑我可能会破坏STH。通过鲁ck以同学的内容切换.UI文件的内容。
这个想法是,GraphicalUI(QOBject)类管理纹理并初始化不同的窗口,在这种情况下,第一个窗口启动屏幕屏幕(QDialog类)以及此之后的MainWindow。

错误消息:

错误消息

compile-error-messages:
debug\moc_graphicalui.cpp:65:46: error: 'staticMetaObject' is not a member of 'AbstractUI'
   65 |     QMetaObject::SuperData::link<AbstractUI::staticMetaObject>(),
      |                                              ^~~~~~~~~~~~~~~~
debug\moc_graphicalui.cpp:65:63: error: no matching function for call to 'QMetaObject::SuperData::link<<expression error> >()'
   65 |     QMetaObject::SuperData::link<AbstractUI::staticMetaObject>(),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:46,
                 from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobjectdefs.h:417:69: note: candidate: 'template<const QMetaObject& MO> static constexpr QMetaObject::SuperData QMetaObject::SuperData::link()'
  417 |         template <const QMetaObject &MO> static constexpr SuperData link()
      |                                                                     ^~~~
C:/Qt/6.2.4/mingw_64/include/QtCore/qobjectdefs.h:417:69: note:   template argument deduction/substitution failed:
debug\moc_graphicalui.cpp:65:63: error: template argument 1 is invalid
   65 |     QMetaObject::SuperData::link<AbstractUI::staticMetaObject>(),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
debug\moc_graphicalui.cpp: In member function 'virtual const QMetaObject* GraphicalUI::metaObject() const':
debug\moc_graphicalui.cpp:82:21: error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected within this context
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                     ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared protected here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp:82:21: error: invalid use of non-static data member 'QObject::d_ptr'
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                     ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp:82:50: error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected within this context
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                                                  ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared protected here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp:82:50: error: invalid use of non-static data member 'QObject::d_ptr'
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                                                  ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp: In member function 'virtual void* GraphicalUI::qt_metacast(const char*)':
debug\moc_graphicalui.cpp:92:24: error: 'qt_metacast' is not a member of 'AbstractUI'
   92 |     return AbstractUI::qt_metacast(_clname);
      |                        ^~~~~~~~~~~
debug\moc_graphicalui.cpp: In member function 'virtual int GraphicalUI::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_graphicalui.cpp:97:23: error: 'qt_metacall' is not a member of 'AbstractUI'
   97 |     _id = AbstractUI::qt_metacall(_c, _id, _a);
      |                       ^~~~~~~~~~~
mingw32-make[1]: *** [Makefile.Debug:2369: debug/moc_graphicalui.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Surface/OneDrive/Old Stuff/Programmieren/build-Prak3Versuch2-Desktop_Qt_6_2_4_MinGW_64_bit-Debug'
mingw32-make: *** [Makefile:45: debug] Error 2
14:21:56: Der Prozess "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" wurde mit dem Rückgabewert 2 beendet.
Fehler beim Erstellen/Deployment des Projekts Prak3Versuch2 (Kit: Desktop Qt 6.2.4 MinGW 64-bit)
Bei der Ausführung von Schritt "Make"
startscreen class class header(qdialog)
#ifndef STARTSCREEN_H
#define STARTSCREEN_H

#include "Header.h"

#include <QLabel>
#include <QDialog>
#include <QPushButton>
#include <QGridLayout>

class GraphicalUI;


namespace Ui { class StartScreen; }

class StartScreen : public QDialog
{
    Q_OBJECT

public:
    explicit StartScreen(GraphicalUI* gUI, QWidget *parent = nullptr);
    ~StartScreen();

    int getBackgroundHeight() const;
    int getBackgroundWidth() const;

private:
    Ui::StartScreen *ui;

    QPushButton *startButton;
    QLabel* backgroundLabel; //label for QPixmap Background
    QPixmap* backgroundPixmap; //Pixmap for Background Texture

    GraphicalUI* graphicalUi;

    void setupDialog();
    void setupStartButton();

private slots:
    void slotSwitchWindow() const;
};

#endif // STARTSCREEN_H
startspreenspreenspreen class。 CPP
#include "startscreen.h"
#include "ui_startscreen.h"
#include "graphicalui.h"

StartScreen::StartScreen(GraphicalUI* gUI, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::StartScreen)
{
    ui->setupUi(this);

    setupDialog();
    setupStartButton();

}

StartScreen::~StartScreen()
{
    delete ui;
}

void StartScreen::setupDialog() {
    backgroundPixmap = graphicalUi->startScreenTextures.at(StartScreenTexturesIndex::BACKGROUND_TEXTURE);
    setWindowTitle(TitleBarLabels::STARTSCREEN_LABEL);

    setFixedSize(QSize(backgroundPixmap->width(), backgroundPixmap->height()));

    backgroundLabel = new QLabel(this);

    ui->dialogGridLayout->addWidget(backgroundLabel, 0 , 0, 5, 3);

    backgroundLabel->setStyleSheet("background-color: rgba(0,0,0,100%)");
    backgroundLabel->setPixmap(*(backgroundPixmap));

}
void StartScreen::setupStartButton() {
    auto buttonPixmap = graphicalUi->startScreenTextures.at(StartScreenTexturesIndex::STARTBUTTON_DEFAULT_TEXTURE);

    startButton = new QPushButton(this);
    startButton->setIcon(*buttonPixmap);

    ui->dialogGridLayout->addWidget(startButton, 3, 1);
}

void StartScreen::slotSwitchWindow() const{
    graphicalUi->switchWindow();
}

int StartScreen::getBackgroundHeight() const {
    return backgroundPixmap->height();
}

int StartScreen::getBackgroundWidth() const {
    return backgroundPixmap->width();
}
启动屏幕类.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>StartScreen</class>
 <widget class="QDialog" name="StartScreen">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QGridLayout" name="dialogGridLayout">
   <property name="leftMargin">
    <number>0</number>
   </property>
   <property name="topMargin">
    <number>0</number>
   </property>
   <property name="rightMargin">
    <number>0</number>
   </property>
   <property name="bottomMargin">
    <number>0</number>
   </property>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

MainWindow类截头
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPixmap>
#include <QLabel>
#include <QGridLayout>
#include <memory>
#include <array>
#include <vector>

#include <iostream>

class GraphicalUI;

namespace Ui { class MainWindow; }

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    explicit MainWindow(GraphicalUI* graphicalUi, QWidget* parent = nullptr);
    ~MainWindow();

private:
    QGridLayout *centralGridLayout;
    Ui::MainWindow* ui;
    GraphicalUI* graphicalUi;
    QLabel* backgroundLabel;

    std::vector<std::vector<QLabel*>> tileLabelsVector;

    QLabel* overlayLabel;

    QGridLayout* buttonGridLayout;
    QGridLayout* levelGridLayout;

    QPixmap* mainWindowOverlay;

    void setupMainWindow();

    void setupOverlay();
};
MainWindow类.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "graphicalui.h"

MainWindow::MainWindow(GraphicalUI* graphicalUi, QWidget* parent) :
    QMainWindow(parent), ui(new Ui::MainWindow), graphicalUi(graphicalUi) {
    ui->setupUi(this);
    centralGridLayout = new QGridLayout(this);
    setupMainWindow();
}

MainWindow::~MainWindow() {
    delete ui;
}

void MainWindow::setupMainWindow() {

    setFixedSize(QSize(mainWindowOverlay->width(), mainWindowOverlay->height()));

    backgroundLabel = new QLabel(this);
    backgroundLabel->setStyleSheet("background-color: rgba(0,0,0,100%)");

    ui->centralGridLayout->addWidget(backgroundLabel,0,0,3,12);

    overlayLabel = new QLabel(this);

    overlayLabel->setStyleSheet("background-color: rgba(0,0,0,0%)");
    overlayLabel->setPixmap(*(mainWindowOverlay));

    ui->centralGridLayout->addWidget(overlayLabel,0,0, 3,12);
}
MainWindow类.UI
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>821</width>
    <height>590</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="centralGridLayout">
    <property name="leftMargin">
     <number>0</number>
    </property>
    <property name="topMargin">
     <number>0</number>
    </property>
    <property name="rightMargin">
     <number>0</number>
    </property>
    <property name="bottomMargin">
     <number>0</number>
    </property>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>821</width>
     <height>20</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

Graphicalui类标头(qObject)
#ifndef GRAPHICALUI_H
#define GRAPHICALUI_H

class Level;

#include <Header.h>
#include <AbstractUI.h>
#include <Controller.h>
#include <QObject>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QGroupBox>
#include <QTextEdit>

#include <startscreen.h>
#include <mainwindow.h>

class GraphicalUI : public AbstractUI, public Controller
{
    Q_OBJECT
public:
    GraphicalUI();
    ~GraphicalUI();

    void move() override;
    char move(Character* who, Level* currentLevel);

    void switchWindow();

    std::vector<QPixmap*> startScreenTextures;
    std::vector<QPixmap*> mainWindowTextures;
    std::vector<QPixmap*> controlButtonTextures;

private:
    StartScreen* startScreen;
    MainWindow* mainWindow;

    void setStartScreenTextures();
    void setTitleBarTextures();
    void setMainWindowTextures();
    void setControlButtonTextures();
};

#endif // GRAPHICALUI_H
Graphicalui类.cpp
#include "graphicalui.h"

GraphicalUI::GraphicalUI()
{
    setStartScreenTextures();
    setMainWindowTextures();
    setControlButtonTextures();

    startScreen = new StartScreen(this);
    mainWindow = new MainWindow(this);
    startScreen->show();
    mainWindow->show();
}


void GraphicalUI::switchWindow(){
    startScreen->hide();
    mainWindow->show();
}


void GraphicalUI::setStartScreenTextures() {
    startScreenTextures.resize(2);

    startScreenTextures.at(StartScreenTexturesIndex::BACKGROUND_TEXTURE) = new QPixmap(StartScreenTextures::BACKGROUND_TEXTURE);
    startScreenTextures.at(StartScreenTexturesIndex::STARTBUTTON_DEFAULT_TEXTURE) = new QPixmap(StartScreenTextures::STARTBUTTON_DEFAULT_TEXTURE);
}

void GraphicalUI::setMainWindowTextures() {
    mainWindowTextures.resize(1);

    mainWindowTextures.at(MainWindowTexturesIndex::MAINWINDOW_OVERLAY_TEXTURE) = new QPixmap(MainWindowTextures::MAINWINDOW_OVERLAY_TEXTURE);
}

void GraphicalUI::setControlButtonTextures() {
    controlButtonTextures.resize(9);

    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_UPLEFT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_UPLEFT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_UP_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_UP_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_UPRIGHT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_UPRIGHT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_LEFT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_LEFT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_SKIP_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_SKIP_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_RIGHT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_RIGHT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_DOWNLEFT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_DOWNLEFT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_DOWN_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_DOWN_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_DOWNRIGHT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_DOWNRIGHT_DEFAULT_TEXTURE);
}

Im trying to add a graphical UI for my dungeon crawler game for an university assignment.
It's my first time using Qt (and first time asking a question here so sorry if it's incoherent, i'll gladly take advice)
And for two days now i'm trying to put sth together with a qDialog, a qMainWindow and a managing qObject class. In between i startet using code from a classmate, cause of time pressure and from there on it became a mess.
I really dont know anymore how to interprete the error messages. So i had hoped that somebody here has the might to simultanously have a hunch what those error messages indicate and how to get out of this situation.
I get no error messages for my code. I suspect i could have broken sth. by having recklessly switching the content of the .ui files with the content from my classmate.
The Idea was, that the GraphicalUI(QObject) class manages the textures and initialises the different windows, in this case the first window StartScreen(QDialog class) and after that MainWindow.

Error Message:

Error Message

Compile-Error-Messages:
debug\moc_graphicalui.cpp:65:46: error: 'staticMetaObject' is not a member of 'AbstractUI'
   65 |     QMetaObject::SuperData::link<AbstractUI::staticMetaObject>(),
      |                                              ^~~~~~~~~~~~~~~~
debug\moc_graphicalui.cpp:65:63: error: no matching function for call to 'QMetaObject::SuperData::link<<expression error> >()'
   65 |     QMetaObject::SuperData::link<AbstractUI::staticMetaObject>(),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:46,
                 from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobjectdefs.h:417:69: note: candidate: 'template<const QMetaObject& MO> static constexpr QMetaObject::SuperData QMetaObject::SuperData::link()'
  417 |         template <const QMetaObject &MO> static constexpr SuperData link()
      |                                                                     ^~~~
C:/Qt/6.2.4/mingw_64/include/QtCore/qobjectdefs.h:417:69: note:   template argument deduction/substitution failed:
debug\moc_graphicalui.cpp:65:63: error: template argument 1 is invalid
   65 |     QMetaObject::SuperData::link<AbstractUI::staticMetaObject>(),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
debug\moc_graphicalui.cpp: In member function 'virtual const QMetaObject* GraphicalUI::metaObject() const':
debug\moc_graphicalui.cpp:82:21: error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected within this context
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                     ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared protected here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp:82:21: error: invalid use of non-static data member 'QObject::d_ptr'
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                     ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp:82:50: error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected within this context
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                                                  ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared protected here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp:82:50: error: invalid use of non-static data member 'QObject::d_ptr'
   82 |     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      |                                                  ^~~~~
In file included from C:/Qt/6.2.4/mingw_64/include/QtCore/QObject:1,
                 from debug\../../Prak3Versuch2/graphicalui.h:9,
                 from debug\moc_graphicalui.cpp:10:
C:/Qt/6.2.4/mingw_64/include/QtCore/qobject.h:415:33: note: declared here
  415 |     QScopedPointer<QObjectData> d_ptr;
      |                                 ^~~~~
debug\moc_graphicalui.cpp: In member function 'virtual void* GraphicalUI::qt_metacast(const char*)':
debug\moc_graphicalui.cpp:92:24: error: 'qt_metacast' is not a member of 'AbstractUI'
   92 |     return AbstractUI::qt_metacast(_clname);
      |                        ^~~~~~~~~~~
debug\moc_graphicalui.cpp: In member function 'virtual int GraphicalUI::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_graphicalui.cpp:97:23: error: 'qt_metacall' is not a member of 'AbstractUI'
   97 |     _id = AbstractUI::qt_metacall(_c, _id, _a);
      |                       ^~~~~~~~~~~
mingw32-make[1]: *** [Makefile.Debug:2369: debug/moc_graphicalui.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Surface/OneDrive/Old Stuff/Programmieren/build-Prak3Versuch2-Desktop_Qt_6_2_4_MinGW_64_bit-Debug'
mingw32-make: *** [Makefile:45: debug] Error 2
14:21:56: Der Prozess "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" wurde mit dem Rückgabewert 2 beendet.
Fehler beim Erstellen/Deployment des Projekts Prak3Versuch2 (Kit: Desktop Qt 6.2.4 MinGW 64-bit)
Bei der Ausführung von Schritt "Make"
Startscreen Class Header (QDialog)
#ifndef STARTSCREEN_H
#define STARTSCREEN_H

#include "Header.h"

#include <QLabel>
#include <QDialog>
#include <QPushButton>
#include <QGridLayout>

class GraphicalUI;


namespace Ui { class StartScreen; }

class StartScreen : public QDialog
{
    Q_OBJECT

public:
    explicit StartScreen(GraphicalUI* gUI, QWidget *parent = nullptr);
    ~StartScreen();

    int getBackgroundHeight() const;
    int getBackgroundWidth() const;

private:
    Ui::StartScreen *ui;

    QPushButton *startButton;
    QLabel* backgroundLabel; //label for QPixmap Background
    QPixmap* backgroundPixmap; //Pixmap for Background Texture

    GraphicalUI* graphicalUi;

    void setupDialog();
    void setupStartButton();

private slots:
    void slotSwitchWindow() const;
};

#endif // STARTSCREEN_H
Startscreen Class .Cpp
#include "startscreen.h"
#include "ui_startscreen.h"
#include "graphicalui.h"

StartScreen::StartScreen(GraphicalUI* gUI, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::StartScreen)
{
    ui->setupUi(this);

    setupDialog();
    setupStartButton();

}

StartScreen::~StartScreen()
{
    delete ui;
}

void StartScreen::setupDialog() {
    backgroundPixmap = graphicalUi->startScreenTextures.at(StartScreenTexturesIndex::BACKGROUND_TEXTURE);
    setWindowTitle(TitleBarLabels::STARTSCREEN_LABEL);

    setFixedSize(QSize(backgroundPixmap->width(), backgroundPixmap->height()));

    backgroundLabel = new QLabel(this);

    ui->dialogGridLayout->addWidget(backgroundLabel, 0 , 0, 5, 3);

    backgroundLabel->setStyleSheet("background-color: rgba(0,0,0,100%)");
    backgroundLabel->setPixmap(*(backgroundPixmap));

}
void StartScreen::setupStartButton() {
    auto buttonPixmap = graphicalUi->startScreenTextures.at(StartScreenTexturesIndex::STARTBUTTON_DEFAULT_TEXTURE);

    startButton = new QPushButton(this);
    startButton->setIcon(*buttonPixmap);

    ui->dialogGridLayout->addWidget(startButton, 3, 1);
}

void StartScreen::slotSwitchWindow() const{
    graphicalUi->switchWindow();
}

int StartScreen::getBackgroundHeight() const {
    return backgroundPixmap->height();
}

int StartScreen::getBackgroundWidth() const {
    return backgroundPixmap->width();
}
Startscreen Class .ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>StartScreen</class>
 <widget class="QDialog" name="StartScreen">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QGridLayout" name="dialogGridLayout">
   <property name="leftMargin">
    <number>0</number>
   </property>
   <property name="topMargin">
    <number>0</number>
   </property>
   <property name="rightMargin">
    <number>0</number>
   </property>
   <property name="bottomMargin">
    <number>0</number>
   </property>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

MainWindow Class Header
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPixmap>
#include <QLabel>
#include <QGridLayout>
#include <memory>
#include <array>
#include <vector>

#include <iostream>

class GraphicalUI;

namespace Ui { class MainWindow; }

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    explicit MainWindow(GraphicalUI* graphicalUi, QWidget* parent = nullptr);
    ~MainWindow();

private:
    QGridLayout *centralGridLayout;
    Ui::MainWindow* ui;
    GraphicalUI* graphicalUi;
    QLabel* backgroundLabel;

    std::vector<std::vector<QLabel*>> tileLabelsVector;

    QLabel* overlayLabel;

    QGridLayout* buttonGridLayout;
    QGridLayout* levelGridLayout;

    QPixmap* mainWindowOverlay;

    void setupMainWindow();

    void setupOverlay();
};
MainWindow Class .Cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "graphicalui.h"

MainWindow::MainWindow(GraphicalUI* graphicalUi, QWidget* parent) :
    QMainWindow(parent), ui(new Ui::MainWindow), graphicalUi(graphicalUi) {
    ui->setupUi(this);
    centralGridLayout = new QGridLayout(this);
    setupMainWindow();
}

MainWindow::~MainWindow() {
    delete ui;
}

void MainWindow::setupMainWindow() {

    setFixedSize(QSize(mainWindowOverlay->width(), mainWindowOverlay->height()));

    backgroundLabel = new QLabel(this);
    backgroundLabel->setStyleSheet("background-color: rgba(0,0,0,100%)");

    ui->centralGridLayout->addWidget(backgroundLabel,0,0,3,12);

    overlayLabel = new QLabel(this);

    overlayLabel->setStyleSheet("background-color: rgba(0,0,0,0%)");
    overlayLabel->setPixmap(*(mainWindowOverlay));

    ui->centralGridLayout->addWidget(overlayLabel,0,0, 3,12);
}
MainWindow Class .ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>821</width>
    <height>590</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="centralGridLayout">
    <property name="leftMargin">
     <number>0</number>
    </property>
    <property name="topMargin">
     <number>0</number>
    </property>
    <property name="rightMargin">
     <number>0</number>
    </property>
    <property name="bottomMargin">
     <number>0</number>
    </property>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>821</width>
     <height>20</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

GraphicalUI Class Header (QObject)
#ifndef GRAPHICALUI_H
#define GRAPHICALUI_H

class Level;

#include <Header.h>
#include <AbstractUI.h>
#include <Controller.h>
#include <QObject>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QGroupBox>
#include <QTextEdit>

#include <startscreen.h>
#include <mainwindow.h>

class GraphicalUI : public AbstractUI, public Controller
{
    Q_OBJECT
public:
    GraphicalUI();
    ~GraphicalUI();

    void move() override;
    char move(Character* who, Level* currentLevel);

    void switchWindow();

    std::vector<QPixmap*> startScreenTextures;
    std::vector<QPixmap*> mainWindowTextures;
    std::vector<QPixmap*> controlButtonTextures;

private:
    StartScreen* startScreen;
    MainWindow* mainWindow;

    void setStartScreenTextures();
    void setTitleBarTextures();
    void setMainWindowTextures();
    void setControlButtonTextures();
};

#endif // GRAPHICALUI_H
GraphicalUI Class .Cpp
#include "graphicalui.h"

GraphicalUI::GraphicalUI()
{
    setStartScreenTextures();
    setMainWindowTextures();
    setControlButtonTextures();

    startScreen = new StartScreen(this);
    mainWindow = new MainWindow(this);
    startScreen->show();
    mainWindow->show();
}


void GraphicalUI::switchWindow(){
    startScreen->hide();
    mainWindow->show();
}


void GraphicalUI::setStartScreenTextures() {
    startScreenTextures.resize(2);

    startScreenTextures.at(StartScreenTexturesIndex::BACKGROUND_TEXTURE) = new QPixmap(StartScreenTextures::BACKGROUND_TEXTURE);
    startScreenTextures.at(StartScreenTexturesIndex::STARTBUTTON_DEFAULT_TEXTURE) = new QPixmap(StartScreenTextures::STARTBUTTON_DEFAULT_TEXTURE);
}

void GraphicalUI::setMainWindowTextures() {
    mainWindowTextures.resize(1);

    mainWindowTextures.at(MainWindowTexturesIndex::MAINWINDOW_OVERLAY_TEXTURE) = new QPixmap(MainWindowTextures::MAINWINDOW_OVERLAY_TEXTURE);
}

void GraphicalUI::setControlButtonTextures() {
    controlButtonTextures.resize(9);

    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_UPLEFT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_UPLEFT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_UP_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_UP_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_UPRIGHT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_UPRIGHT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_LEFT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_LEFT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_SKIP_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_SKIP_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_RIGHT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_RIGHT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_DOWNLEFT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_DOWNLEFT_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_DOWN_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_DOWN_DEFAULT_TEXTURE);
    controlButtonTextures.at(ControlButtonTexturesIndex::CONTROLBUTTON_DOWNRIGHT_DEFAULT_TEXTURE) = new QPixmap(ControlButtonTextures::CONTROLBUTTON_DOWNRIGHT_DEFAULT_TEXTURE);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小鸟爱天空丶 2025-02-15 13:36:49

希望清除任何混乱,QT的基本知识就是这样:

  • 所有QOBject类都必须从QOBject(或派生的类)公开继承,并在其私有部分中具有q_object宏;
  • 使用Qmake,必须在项目文件中的标题下列出标题。 CMAKE可以直接在目标源列表中列出的汽车标头文件,以及与源(.cpp)文件相对应的列表;
  • 当一类具有此宏,但不是qobject时,汇编将失败。

To hopefully clear up any confusion, Qt's basics are like this:

  • All QObject classes must publicly inherit from QObject (or a derived class) and have the Q_OBJECT macro in their private sections;
  • With qmake, headers must be listed under HEADERS in the project file. CMake can automoc header files listed directly in a target's source list, plus those corresponding to source (.cpp) files;
  • Compilation will fail when a class has this macro, but is not a QObject.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文