QML opens GUI window and console

1.5k Views Asked by At

I'm trying to get a working QML app. It's all fine except the fact that when I run my app it opens the QML window but also a console window. Why? This is the code:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QDeclarativeView view;

    view.setSource(QUrl::fromLocalFile("myfile.qml"));
    view.show();

    return app.exec();
}

Rectangle {
    width: 940
    height: 670
    color: red
}
3

There are 3 best solutions below

0
On

The console is for debugging with QDebug();

You can disable it by deleting line:

CONFIG += console

in your .pro file.

0
On

For CMake users.

The problems occurred to me for MSVC and MinGW builds for Windows. (Even when not starting from an IDE.)

The solution were the following lines in CMakeLists:

if (WIN32)
    set(WIN32_ON_OFF_SWITCH "WIN32")
else ()
    set(WIN32_ON_OFF_SWITCH "")
endif ()

add_executable(SomeExe
    ${WIN32_ON_OFF_SWITCH}
    #...
)

This exactly sets the target system away from console, like mentioned in a comment to the question.

0
On

For qbs set the property
consoleApplication: false
for your application. For example:

    Application {
    // consoleApplication: false // permanently disable the console for the application
    Properties {
        condition: qbs.buildVariant == "debug"
        consoleApplication: true //show console
    }

    Properties {
        condition: qbs.buildVariant == "release"
        consoleApplication: false //hide console
    }
}