ich habe heute meine erste QML-Application geschrieben.
Ein simples Window mit dem Titel "Hello World".
Wenn ich es im Qt-Creator laufen lasse (also den Start-Button drücke), dann erscheint das Fenster wie erwartet.
Wenn ich das Programm aus einer Console heraus starte, dann aber leider nicht.
Es hat den Eindruck, das das Programm startet und sich gleich wieder beendet, aber das kann ich nicht mit Gewissheit sagen.
Wie bekomme ich das kleine Test-Programm aus der Konsole heraus gestartet?
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "QDebug"
Hier das main programm
Code: Alles auswählen
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
const QUrl urlAppPath(QString("%1").arg(app.applicationDirPath()));
// show the application path
qDebug() << "application path: " << urlAppPath;
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();
} // main
Code: Alles auswählen
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}