0

I converted my .ui file via uic into a header file, which, as far as I know, contains the header AND the implementation of the .ui file. But what part of it is the header and what is the implementation? Is there a way to seperate them properly?

#ifndef PATCHBOT_GUI_H
#define PATCHBOT_GUI_H

#include <QtCore/QVariant>
#include <QtGui/QIcon>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_MainWindow
{
public:
    QWidget *centralwidget;
    QGridLayout *gridLayout;
    QFrame *selectColonyFrame;
    QPushButton *selectColonyButton;
    QFrame *currentColonyFrame;
    QLabel *currentColonyLabel;
    QFrame *missionControlsFrame;
    QVBoxLayout *verticalLayout;
    QLabel *misisonControlsLabel;
    QGridLayout *missionControlsGridLayout;
    QPushButton *startButton;
    QPushButton *abortButton;
    QPushButton *singleStepButton;
    QPushButton *autoButton;
    QPushButton *pauseButton;
    QFrame *botControlsFrame;
    QGridLayout *gridLayout_2;
    QGridLayout *botControlsGridLayout;
    QPushButton *downButton;
    QPushButton *upButton;
    QPushButton *waitButton;
    QPushButton *leftButton;
    QPushButton *deleteButton;
    QPushButton *rightButton;
    QLabel *botControlsLabel;
    QComboBox *repeatDropdown;
    QFrame *frame_6;
    QFrame *botCommandFrame;
    QTextEdit *botCommandTextEdit;
    QFrame *mapFrame;
    QGridLayout *gridLayout_6;
    QLabel *label;
    QScrollBar *verticalScrollBar;
    QScrollBar *horizontalScrollBar;
    QMenuBar *menubar;
    QStatusBar *statusbar;

    void setupUi(QMainWindow *MainWindow)
    {
        if (MainWindow->objectName().isEmpty())
            MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
        MainWindow->resize(819, 634);
        MainWindow->setMinimumSize(QSize(580, 400));
        centralwidget = new QWidget(MainWindow);
        centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
        gridLayout = new QGridLayout(centralwidget);
        gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
        gridLayout->setVerticalSpacing(6);
        gridLayout->setContentsMargins(-1, 0, -1, 0);
        selectColonyFrame = new QFrame(centralwidget);
        selectColonyFrame->setObjectName(QString::fromUtf8("selectColonyFrame"));
        selectColonyFrame->setMinimumSize(QSize(150, 40));
        selectColonyFrame->setLayoutDirection(Qt::RightToLeft);
        selectColonyFrame->setFrameShape(QFrame::StyledPanel);
        selectColonyFrame->setFrameShadow(QFrame::Raised);
        selectColonyButton = new QPushButton(selectColonyFrame);
        selectColonyButton->setObjectName(QString::fromUtf8("selectColonyButton"));
        selectColonyButton->setGeometry(QRect(80, 0, 150, 40));
        selectColonyButton->setMinimumSize(QSize(150, 40));
        selectColonyButton->setMaximumSize(QSize(150, 50));
        QFont font;
        font.setPointSize(11);
        font.setBold(true);
        font.setWeight(75);
        selectColonyButton->setFont(font);

        gridLayout->addWidget(selectColonyFrame, 0, 1, 1, 1);

        currentColonyFrame = new QFrame(centralwidget);
        currentColonyFrame->setObjectName(QString::fromUtf8("currentColonyFrame"));
        QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
        sizePolicy.setHorizontalStretch(0);
        sizePolicy.setVerticalStretch(0);
        sizePolicy.setHeightForWidth(currentColonyFrame->sizePolicy().hasHeightForWidth());
        currentColonyFrame->setSizePolicy(sizePolicy);
        currentColonyFrame->setMinimumSize(QSize(0, 25));
        currentColonyFrame->setFrameShape(QFrame::StyledPanel);
        currentColonyFrame->setFrameShadow(QFrame::Raised);
        currentColonyLabel = new QLabel(currentColonyFrame);
        currentColonyLabel->setObjectName(QString::fromUtf8("currentColonyLabel"));
        currentColonyLabel->setGeometry(QRect(10, 10, 301, 16));
        currentColonyLabel->setMinimumSize(QSize(220, 15));
        currentColonyLabel->setMaximumSize(QSize(460, 25));
        QFont font1;
        font1.setPointSize(10);
        currentColonyLabel->setFont(font1);

        gridLayout->addWidget(currentColonyFrame, 0, 0, 1, 1);

        missionControlsFrame = new QFrame(centralwidget);
        missionControlsFrame->setObjectName(QString::fromUtf8("missionControlsFrame"));
        QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
        sizePolicy1.setHorizontalStretch(8);
        sizePolicy1.setVerticalStretch(8);
        sizePolicy1.setHeightForWidth(missionControlsFrame->sizePolicy().hasHeightForWidth());
        missionControlsFrame->setSizePolicy(sizePolicy1);
        missionControlsFrame->setMaximumSize(QSize(300, 180));
        missionControlsFrame->setFrameShape(QFrame::WinPanel);
        missionControlsFrame->setFrameShadow(QFrame::Raised);
        verticalLayout = new QVBoxLayout(missionControlsFrame);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
        misisonControlsLabel = new QLabel(missionControlsFrame);
        misisonControlsLabel->setObjectName(QString::fromUtf8("misisonControlsLabel"));
        QFont font2;
        font2.setPointSize(11);
        misisonControlsLabel->setFont(font2);
        misisonControlsLabel->setAlignment(Qt::AlignCenter);

        verticalLayout->addWidget(misisonControlsLabel);

        missionControlsGridLayout = new QGridLayout();
        missionControlsGridLayout->setObjectName(QString::fromUtf8("missionControlsGridLayout"));
        missionControlsGridLayout->setHorizontalSpacing(20);
        missionControlsGridLayout->setVerticalSpacing(10);
        missionControlsGridLayout->setContentsMargins(15, 20, 15, 0);
        startButton = new QPushButton(missionControlsFrame);
        startButton->setObjectName(QString::fromUtf8("startButton"));
        startButton->setMinimumSize(QSize(80, 30));
        startButton->setMaximumSize(QSize(130, 50));
        QFont font3;
        font3.setPointSize(12);
        startButton->setFont(font3);

        missionControlsGridLayout->addWidget(startButton, 0, 0, 1, 1);

        abortButton = new QPushButton(missionControlsFrame);
        abortButton->setObjectName(QString::fromUtf8("abortButton"));
        abortButton->setMinimumSize(QSize(80, 30));
        abortButton->setMaximumSize(QSize(130, 50));
        abortButton->setFont(font3);
        abortButton->setLayoutDirection(Qt::LeftToRight);
        abortButton->setAutoDefault(false);
        abortButton->setFlat(false);

        missionControlsGridLayout->addWidget(abortButton, 0, 1, 1, 1);

        singleStepButton = new QPushButton(missionControlsFrame);
        singleStepButton->setObjectName(QString::fromUtf8("singleStepButton"));
        singleStepButton->setMinimumSize(QSize(80, 30));
        singleStepButton->setMaximumSize(QSize(130, 50));
        singleStepButton->setFont(font3);

        missionControlsGridLayout->addWidget(singleStepButton, 1, 0, 1, 1);

        autoButton = new QPushButton(missionControlsFrame);
        autoButton->setObjectName(QString::fromUtf8("autoButton"));
        autoButton->setMinimumSize(QSize(80, 30));
        autoButton->setMaximumSize(QSize(130, 50));
        autoButton->setFont(font3);
        autoButton->setLayoutDirection(Qt::LeftToRight);
        autoButton->setAutoDefault(false);
        autoButton->setFlat(false);

        missionControlsGridLayout->addWidget(autoButton, 1, 1, 1, 1);

        pauseButton = new QPushButton(missionControlsFrame);
        pauseButton->setObjectName(QString::fromUtf8("pauseButton"));
        pauseButton->setMinimumSize(QSize(80, 30));
        pauseButton->setMaximumSize(QSize(130, 50));
        pauseButton->setFont(font3);
        pauseButton->setLayoutDirection(Qt::LeftToRight);
        pauseButton->setAutoDefault(false);
        pauseButton->setFlat(false);

        missionControlsGridLayout->addWidget(pauseButton, 2, 1, 1, 1);


        verticalLayout->addLayout(missionControlsGridLayout);


        gridLayout->addWidget(missionControlsFrame, 3, 1, 1, 1);

        botControlsFrame = new QFrame(centralwidget);
        botControlsFrame->setObjectName(QString::fromUtf8("botControlsFrame"));
        QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Preferred);
        sizePolicy2.setHorizontalStretch(4);
        sizePolicy2.setVerticalStretch(4);
        sizePolicy2.setHeightForWidth(botControlsFrame->sizePolicy().hasHeightForWidth());
        botControlsFrame->setSizePolicy(sizePolicy2);
        botControlsFrame->setMinimumSize(QSize(160, 120));
        botControlsFrame->setMaximumSize(QSize(320, 240));
        botControlsFrame->setFrameShape(QFrame::WinPanel);
        botControlsFrame->setFrameShadow(QFrame::Raised);
        gridLayout_2 = new QGridLayout(botControlsFrame);
        gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
        botControlsGridLayout = new QGridLayout();
        botControlsGridLayout->setObjectName(QString::fromUtf8("botControlsGridLayout"));
        botControlsGridLayout->setSizeConstraint(QLayout::SetMinimumSize);
        downButton = new QPushButton(botControlsFrame);
        downButton->setObjectName(QString::fromUtf8("downButton"));
        downButton->setMinimumSize(QSize(30, 30));
        downButton->setMaximumSize(QSize(50, 50));
        downButton->setLayoutDirection(Qt::LeftToRight);
        QIcon icon;
        icon.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_unten.tga"), QSize(), QIcon::Normal, QIcon::Off);
        downButton->setIcon(icon);
        downButton->setIconSize(QSize(50, 50));

        botControlsGridLayout->addWidget(downButton, 2, 1, 1, 1);

        upButton = new QPushButton(botControlsFrame);
        upButton->setObjectName(QString::fromUtf8("upButton"));
        upButton->setMinimumSize(QSize(30, 30));
        upButton->setMaximumSize(QSize(50, 50));
        upButton->setSizeIncrement(QSize(0, 0));
        QIcon icon1;
        icon1.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_oben.tga"), QSize(), QIcon::Normal, QIcon::Off);
        upButton->setIcon(icon1);
        upButton->setIconSize(QSize(50, 50));

        botControlsGridLayout->addWidget(upButton, 0, 1, 1, 1);

        waitButton = new QPushButton(botControlsFrame);
        waitButton->setObjectName(QString::fromUtf8("waitButton"));
        waitButton->setMinimumSize(QSize(30, 30));
        waitButton->setMaximumSize(QSize(50, 50));
        QFont font4;
        font4.setFamily(QString::fromUtf8("MS Shell Dlg 2"));
        font4.setPointSize(15);
        waitButton->setFont(font4);
        waitButton->setContextMenuPolicy(Qt::DefaultContextMenu);
        QIcon icon2;
        QString iconThemeName = QString::fromUtf8("&#9664");
        if (QIcon::hasThemeIcon(iconThemeName)) {
            icon2 = QIcon::fromTheme(iconThemeName);
        } else {
            icon2.addFile(QString::fromUtf8("."), QSize(), QIcon::Normal, QIcon::Off);
        }
        waitButton->setIcon(icon2);

        botControlsGridLayout->addWidget(waitButton, 1, 1, 1, 1);

        leftButton = new QPushButton(botControlsFrame);
        leftButton->setObjectName(QString::fromUtf8("leftButton"));
        leftButton->setMinimumSize(QSize(30, 30));
        leftButton->setMaximumSize(QSize(50, 50));
        QIcon icon3;
        icon3.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_links.tga"), QSize(), QIcon::Normal, QIcon::Off);
        leftButton->setIcon(icon3);
        leftButton->setIconSize(QSize(50, 50));

        botControlsGridLayout->addWidget(leftButton, 1, 0, 1, 1);

        deleteButton = new QPushButton(botControlsFrame);
        deleteButton->setObjectName(QString::fromUtf8("deleteButton"));
        deleteButton->setMinimumSize(QSize(30, 30));
        deleteButton->setMaximumSize(QSize(50, 50));
        QFont font5;
        font5.setPointSize(15);
        deleteButton->setFont(font5);

        botControlsGridLayout->addWidget(deleteButton, 0, 2, 1, 1);

        rightButton = new QPushButton(botControlsFrame);
        rightButton->setObjectName(QString::fromUtf8("rightButton"));
        rightButton->setMinimumSize(QSize(30, 30));
        rightButton->setMaximumSize(QSize(50, 50));
        rightButton->setSizeIncrement(QSize(0, 0));
        QIcon icon4;
        icon4.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_rechts.tga"), QSize(), QIcon::Normal, QIcon::Off);
        rightButton->setIcon(icon4);
        rightButton->setIconSize(QSize(50, 50));

        botControlsGridLayout->addWidget(rightButton, 1, 2, 1, 1);


        gridLayout_2->addLayout(botControlsGridLayout, 1, 0, 3, 1);

        botControlsLabel = new QLabel(botControlsFrame);
        botControlsLabel->setObjectName(QString::fromUtf8("botControlsLabel"));
        botControlsLabel->setFont(font2);
        botControlsLabel->setAlignment(Qt::AlignCenter);

        gridLayout_2->addWidget(botControlsLabel, 0, 0, 1, 2);

        repeatDropdown = new QComboBox(botControlsFrame);
        repeatDropdown->addItem(QString());
        repeatDropdown->addItem(QString());
        repeatDropdown->addItem(QString());
        repeatDropdown->addItem(QString());
        repeatDropdown->addItem(QString());
        repeatDropdown->setObjectName(QString::fromUtf8("repeatDropdown"));
        repeatDropdown->setMinimumSize(QSize(80, 30));
        repeatDropdown->setMaximumSize(QSize(130, 50));
        QFont font6;
        font6.setPointSize(15);
        font6.setBold(true);
        font6.setItalic(false);
        font6.setWeight(75);
        repeatDropdown->setFont(font6);
        repeatDropdown->setFocusPolicy(Qt::WheelFocus);
        repeatDropdown->setLayoutDirection(Qt::LeftToRight);
        repeatDropdown->setInsertPolicy(QComboBox::NoInsert);
        repeatDropdown->setFrame(true);

        gridLayout_2->addWidget(repeatDropdown, 1, 1, 1, 1);

        frame_6 = new QFrame(botControlsFrame);
        frame_6->setObjectName(QString::fromUtf8("frame_6"));
        frame_6->setFrameShape(QFrame::StyledPanel);
        frame_6->setFrameShadow(QFrame::Raised);

        gridLayout_2->addWidget(frame_6, 2, 1, 1, 1);

        botCommandFrame = new QFrame(botControlsFrame);
        botCommandFrame->setObjectName(QString::fromUtf8("botCommandFrame"));
        botCommandFrame->setMinimumSize(QSize(100, 80));
        botCommandFrame->setMaximumSize(QSize(130, 16777215));
        botCommandFrame->setFrameShape(QFrame::StyledPanel);
        botCommandFrame->setFrameShadow(QFrame::Raised);
        botCommandTextEdit = new QTextEdit(botCommandFrame);
        botCommandTextEdit->setObjectName(QString::fromUtf8("botCommandTextEdit"));
        botCommandTextEdit->setGeometry(QRect(0, 16, 108, 50));
        QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding);
        sizePolicy3.setHorizontalStretch(130);
        sizePolicy3.setVerticalStretch(50);
        sizePolicy3.setHeightForWidth(botCommandTextEdit->sizePolicy().hasHeightForWidth());
        botCommandTextEdit->setSizePolicy(sizePolicy3);
        botCommandTextEdit->setMinimumSize(QSize(80, 30));
        botCommandTextEdit->setMaximumSize(QSize(130, 50));
        botCommandTextEdit->setFont(font5);
        botCommandTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        botCommandTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        botCommandTextEdit->setLineWrapMode(QTextEdit::NoWrap);
        botCommandTextEdit->setReadOnly(true);

        gridLayout_2->addWidget(botCommandFrame, 3, 1, 1, 1);

        gridLayout_2->setRowStretch(1, 2);
        gridLayout_2->setRowStretch(2, 1);
        gridLayout_2->setRowStretch(3, 1);

        gridLayout->addWidget(botControlsFrame, 1, 1, 2, 1);

        mapFrame = new QFrame(centralwidget);
        mapFrame->setObjectName(QString::fromUtf8("mapFrame"));
        QSizePolicy sizePolicy4(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
        sizePolicy4.setHorizontalStretch(0);
        sizePolicy4.setVerticalStretch(0);
        sizePolicy4.setHeightForWidth(mapFrame->sizePolicy().hasHeightForWidth());
        mapFrame->setSizePolicy(sizePolicy4);
        mapFrame->setMinimumSize(QSize(120, 120));
        mapFrame->setFrameShape(QFrame::StyledPanel);
        mapFrame->setFrameShadow(QFrame::Raised);
        gridLayout_6 = new QGridLayout(mapFrame);
        gridLayout_6->setSpacing(0);
        gridLayout_6->setObjectName(QString::fromUtf8("gridLayout_6"));
        label = new QLabel(mapFrame);
        label->setObjectName(QString::fromUtf8("label"));
        sizePolicy4.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
        label->setSizePolicy(sizePolicy4);
        label->setMinimumSize(QSize(0, 0));
        label->setFrameShape(QFrame::Box);
        label->setAlignment(Qt::AlignCenter);

        gridLayout_6->addWidget(label, 0, 0, 1, 1);

        verticalScrollBar = new QScrollBar(mapFrame);
        verticalScrollBar->setObjectName(QString::fromUtf8("verticalScrollBar"));
        verticalScrollBar->setOrientation(Qt::Vertical);

        gridLayout_6->addWidget(verticalScrollBar, 0, 1, 1, 1);

        horizontalScrollBar = new QScrollBar(mapFrame);
        horizontalScrollBar->setObjectName(QString::fromUtf8("horizontalScrollBar"));
        QSizePolicy sizePolicy5(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
        sizePolicy5.setHorizontalStretch(0);
        sizePolicy5.setVerticalStretch(0);
        sizePolicy5.setHeightForWidth(horizontalScrollBar->sizePolicy().hasHeightForWidth());
        horizontalScrollBar->setSizePolicy(sizePolicy5);
        horizontalScrollBar->setOrientation(Qt::Horizontal);

        gridLayout_6->addWidget(horizontalScrollBar, 1, 0, 1, 1);


        gridLayout->addWidget(mapFrame, 1, 0, 3, 1);

        gridLayout->setRowStretch(0, 1);
        gridLayout->setRowStretch(1, 4);
        gridLayout->setRowStretch(2, 4);
        gridLayout->setColumnStretch(0, 2);
        gridLayout->setColumnMinimumWidth(0, 1);
        gridLayout->setColumnMinimumWidth(1, 1);
        gridLayout->setRowMinimumHeight(0, 1);
        gridLayout->setRowMinimumHeight(1, 1);
        gridLayout->setRowMinimumHeight(2, 10);
        gridLayout->setRowMinimumHeight(3, 1);
        MainWindow->setCentralWidget(centralwidget);
        menubar = new QMenuBar(MainWindow);
        menubar->setObjectName(QString::fromUtf8("menubar"));
        menubar->setGeometry(QRect(0, 0, 819, 20));
        MainWindow->setMenuBar(menubar);
        statusbar = new QStatusBar(MainWindow);
        statusbar->setObjectName(QString::fromUtf8("statusbar"));
        MainWindow->setStatusBar(statusbar);

        retranslateUi(MainWindow);

        abortButton->setDefault(false);
        autoButton->setDefault(false);
        pauseButton->setDefault(false);


        QMetaObject::connectSlotsByName(MainWindow);
    } // setupUi

    void retranslateUi(QMainWindow *MainWindow)
    {
        MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
        selectColonyButton->setText(QCoreApplication::translate("MainWindow", "Andere Kolonie ...", nullptr));
        currentColonyLabel->setText(QCoreApplication::translate("MainWindow", "Aktuelle Kolonie: Lithium-Stollen 13-A", nullptr));
        misisonControlsLabel->setText(QCoreApplication::translate("MainWindow", "Missionsablauf", nullptr));
        startButton->setText(QCoreApplication::translate("MainWindow", "Start", nullptr));
        abortButton->setText(QCoreApplication::translate("MainWindow", "Abbruch", nullptr));
        singleStepButton->setText(QCoreApplication::translate("MainWindow", "Einzelschritt", nullptr));
        autoButton->setText(QCoreApplication::translate("MainWindow", "Automatik", nullptr));
        pauseButton->setText(QCoreApplication::translate("MainWindow", "Anhalten", nullptr));
        downButton->setText(QString());
        upButton->setText(QString());
        waitButton->setText(QCoreApplication::translate("MainWindow", "W", nullptr));
        leftButton->setText(QString());
        deleteButton->setText(QCoreApplication::translate("MainWindow", "<", nullptr));
        rightButton->setText(QString());
        botControlsLabel->setText(QCoreApplication::translate("MainWindow", "Programmieren", nullptr));
        repeatDropdown->setItemText(0, QCoreApplication::translate("MainWindow", "1", nullptr));
        repeatDropdown->setItemText(1, QCoreApplication::translate("MainWindow", "2", nullptr));
        repeatDropdown->setItemText(2, QCoreApplication::translate("MainWindow", "3", nullptr));
        repeatDropdown->setItemText(3, QCoreApplication::translate("MainWindow", "4", nullptr));
        repeatDropdown->setItemText(4, QCoreApplication::translate("MainWindow", "5", nullptr));

        repeatDropdown->setCurrentText(QCoreApplication::translate("MainWindow", "1", nullptr));
        botCommandTextEdit->setPlaceholderText(QCoreApplication::translate("MainWindow", "Textfeld", nullptr));
        label->setText(QCoreApplication::translate("MainWindow", "Umgebungskarte", nullptr));
    } // retranslateUi

};

namespace Ui {
    class MainWindow: public Ui_MainWindow {};
} // namespace Ui

QT_END_NAMESPACE

#endif // PATCHBOT_GUI_H

Since I'm working with VS 2019 and have the "QT VS Tools" extension installed, I could also use the new "Convert Project to Qmake generated Project" tool. The problem here is, that I don't really know how it works. I opened my .pro file from Qt Designer with the "Open Qt project file..." funciton and then used the tool mentioned above. After the process finished, I didn't see any changes or new files. Did I miss something? Do I need to do something else?

If further information is needed, I'd be happy to help.

Cpt. Crazy
  • 115
  • 1
  • 11
  • You might want to read a Qt tutorial. Or a few minutes to look at the project in the [Qt Creator IDE](https://en.wikipedia.org/wiki/Qt_Creator) to look at the project structure and see what files it have, and follow that layout and setup with your own project in e.g. Visual Studio. For example, your customization and implementation of the `MainWindow` (and the `MainWindow` class itself) is in a `MainWindow.h` header file, which includes the auto-generated header file, and a `MainWindow.cpp` source file. – Some programmer dude Dec 06 '19 at 18:39
  • I've the Wikipedia article (except the history part) and I can't seem to find something helping me here :/ – Cpt. Crazy Dec 06 '19 at 18:46
  • Could anyone specify what to do? I'm out of ideas sadly and haven't quite found a lot searching the web – Cpt. Crazy Dec 06 '19 at 21:19
  • Please check [the official examples and tutorials](https://doc.qt.io/qt-5/qtexamplesandtutorials.html). Perhaps start with the relative simple [single main window example](https://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html) whose full source code is [here](https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/mainwindows/application?h=5.13). – Some programmer dude Dec 06 '19 at 21:23
  • @Someprogrammerdude I've looked through some examples, but the problem is, that they are all based on creating uis only by code and not with Qt Designer. I already have the my ui completed, I "just" need a way to convert the XML code into useable C++ code. And I already did so by using `uic`, I'm just not sure which part of the resulting file is the header and which implementation. If I've missed something about converting one into the other on the websites, I stand corrected, but I'd be happy, if you'd show me, where exactly to find that. – Cpt. Crazy Dec 06 '19 at 23:14

1 Answers1

0

Basically the minimal Qt stand-alone example is two source files, one header file, and the UI XML file:

  • There's the "main" Source file which contains the main function
  • There's a "main window" source file which contains the implementation for the main window
  • There's the "main window" header file
  • And as mentioned there's the UI XML file

The "main" source file could be very simple, all it does is create a QApplication object and the MainWindow object. It shows the main window and then enters the application event loop:

#include <QApplication>
#include "MainWindow.h"

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    MainWindow window;

    window.show();  // Show the main window

    return app.exec();  // Run the application event loop
}

The "main window" header file start out also very simple:

#include <QMainWindow>

namespace Ui
{
    class MainWindow;  // This is the "main window" from the UI XML file
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget* parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow* ui;  // Pointer to the UI generated by the XML file and the uic program
};

And finally the "main window" implementation source file:

#include "MainWindow.h"
#include "ui_mainwindow.h"  // This is the automatically generated header file created by uic

MainWindow::MainWindow(QWidget* parent /* = nullptr */)
    : QMainWindow(parent),
      ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

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

You also need to run the uic program to generate the needed source files from the UI XML file, and then build with the source file. You also need to use the moc tool to resolve slots and signals.

All of this should really be in most tutorials you will find online.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • So what you're saying is, that I don't need to convert the UI XML file into c++ code. I just need those 4 files and I can then access any parameter and change any value by referring to them e.g. in the "main window" implementation source file. For example: change the maximum width of my window? – Cpt. Crazy Dec 07 '19 at 00:56
  • @Cpt.Crazy No you definitely need to run the `uic` program to create the autogenerated source files for your window. That is what will be creating the `ui_mainwindow` (or whatever they're named) source and header files that you need to build with. – Some programmer dude Dec 07 '19 at 10:43
  • Sorry to answer so incredibly late: You're talking about "autogenerated source files" in plural, should the `uic` program create more than that one `.h` file, that I've got? – Cpt. Crazy Dec 12 '19 at 19:36
  • @Cpt.Crazy I don't remember how many "spurce" (`.cpp`, `.h` or others) that the `uic` tool create. I think that the `moc` tool also creates some source files. You need to read the documentation for those tools (and use them to see what they do) to find out more. – Some programmer dude Dec 12 '19 at 20:20
  • Ok I looked it up [here](https://doc.qt.io/archives/qt-4.8/uic.html) and its supposed to only create that one header file. In advance I'm sorry I have to ask so much, but don't know what to do. When opening the header file in VS2019, it doesn't recognize/ can't import Qt libraries like `QtPushButton` or any other of those qt libraries. I'm currently downloading VS2017, cause I found out that there should be a Qt extension I can't find in VS2019, and maybe it'll work using VS2017 – Cpt. Crazy Dec 12 '19 at 20:57
  • I've tried to work it out somehow with VS2019 or VS2017, but none of those seem to be able to import the Qt libraries like mentioned above. Any ideas? Maybe I should ask this in a new question since that is not quite what I asked here – Cpt. Crazy Dec 12 '19 at 22:43