Vira
Vira

Reputation: 1

A new Qt widget application will not compile

I am relatively new to Qt and was going through many tutorials. Everything was fine. All scripts compiled and ran. Then, at some point, I am getting the error for even a new Qt widget application created with Qt Creator 4.3.1:

C:\  \Documents\111\main.cpp:-1: In function 'int qMain(int, char**)':
C:\   \Documents\111\main.cpp:6: error: variable 'QApplication a' has initializer but incomplete type
     QApplication a(argc, argv);
                    ^
C:\   \Documents\111\main.cpp:11: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

I am not sure what happened, yet seems like some setups were messed up. QApplication is included, and not missing in the script.

111.pro
# Project created by QtCreator 2018-02-23T01:36:28
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 111
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

main.cpp
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}

mainview.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"

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

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

It seems to me that this issue appeared after trying to run qt5.6_src.zip examples from https://en.ids-imaging.com/open-source.html.

Upvotes: 0

Views: 593

Answers (3)

Vira
Vira

Reputation: 1

The issue is fixed by deleting the Qt folder and QtCreator folder in the <drive>:\Users\<username>\AppData\Roaming\QtProject and <drive>:\Users\<username>\AppData\Roaming\Qt. It stored incorrect settings, which I somehow setup by running open source scripts. For more information visit Where does QtCreator save its settings?.

Upvotes: 0

JustWe
JustWe

Reputation: 4484

Without completed code, I guess you need to add #include <QApplication> to main.cpp

The error message told you what is missing.

Upvotes: 1

RAM
RAM

Reputation: 2759

According to Qt's docs, the constructor's signature is QApplication(int &argc, char **argv). Therefore, if you inherit from QApplication then the subclass's constructor must pass argc by reference. From your description, it appears that the constructor of your subclass is actually passing argc by value (i.e., int qMain(int, char**) ). That will cause some problems.

Upvotes: 0

Related Questions