'How do I run a program in QT creator?

Installed the QT creator program Now, first of all, I'm just trying to run the first code through QML: main.qml:

import QtQuick 2.12
import QtQuick.Window 2.12
Window {
    id: root
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    Tile {
        width: root.width / 4
        height: root.height / 4
    }
}

Tile.qml:

import QtQuick 2.0
Rectangle {
    id: root
    color: "lightgreen"
    radius: 10
    border.color: "black"
    border.width: 1
    Text {
        id: _firstText
        anchors.centerIn: root
        text: "1"
        font {
            pointSize: Math.min(root.width, root.height) / 3
            bold: true
        }
    }
}

Gives the following error:

**Project ERROR: Unknown module(s) in QT: quick**

And the second code through the console application: main.cpp:

#include <iostream>
using namespace std;
int main() {
    cout << "Hello wolrd" << endl;
    return 0;
}

Gives the following error:

**

13:23:56: Starting /home/[email protected]/Рабочий стол/Hello/git/Cpp/Test2/build-Test-Desktop-Debug/Test ...
13:23:56: An unknown error in the process occurred.
13:23:56: Cannot start the terminal emulator "xterm", change the setting in the Environment options.
13:23:56: /home/[email protected]/Рабочий стол/Hello/git/Cpp/Test2/build-Test-Desktop-Debug/Test exited with code -1

** What to do? everything was running great on windows



Solution 1:[1]

I test your code, you probably didn't add QT += quick qml in your .pro or you have some mistakes in main.cpp, If you do all of this then your problem relates to your installation.

This is my Test:

1..pro

QT += quick qml

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
        main.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

2.in main.qml :

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    id: root
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    Tile {
        width: root.width / 4
        height: root.height / 4
    }
}

3.in Tile.qml

import QtQuick 2.0
Rectangle {
    id: root
    color: "lightgreen"
    radius: 10
    border.color: "black"
    border.width: 1
    Text {
        id: _firstText
        anchors.centerIn: root
        text: "1"
        font {
            pointSize: Math.min(root.width, root.height) / 3
            bold: true
        }
    }
}

4.in main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>


int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}

This is the output

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Parisa.H.R