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:
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);
}
To hopefully clear up any confusion, Qt's basics are like this:
HEADERSin the project file. CMake can automoc header files listed directly in a target's source list, plus those corresponding to source (.cpp) files;