0

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.

Vira
  • 1
  • 3
  • First, please take the [tour]. Second, show the code that leads to the error message; don't dump the complete project but make it a [mcve] including the `.pro` file. – Murphy Feb 23 '18 at 09:08
  • @NikosC. Do you think this makes a difference? Why? – Murphy Feb 23 '18 at 09:22

3 Answers3

1

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

The error message told you what is missing.

JustWe
  • 4,250
  • 3
  • 39
  • 90
  • Thanks @Jiu. The problem is that the `#include ` is there in `main.cpp`. But the code does not compile with the mentioned error. – Vira Feb 23 '18 at 22:59
0

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.

RAM
  • 2,257
  • 2
  • 19
  • 41
0

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?.

Vira
  • 1
  • 3