Projects with QML Compile Blank
-
First off, this is my first post here and I haven't been around forums for a while so apologies if I mess up with the etiquette here
So any project containing a .qml file compiles without error but QML elements do not display. In their place is blank white space. This occurs with new projects as well as example projects included with Qt Creator.
I've searched google for this problem and found people having similar issues when their .qml files are not included correctly in a resource file or the path in their source code isn't right but neither of those issues apply with my problem. It occurs regardless of how the file path is specified in source and occurs with example/tutorial projects with properly formatted resource files.
Really, all the discussion I find when I search for solutions seems to be about tangentially related issues that don't match with mine, so I'm kinda at a loss here. Also I encountered this issue while I had just started fiddling around with QML so I don't know what I don't know here, much less what info would be helpful.
Any ideas?
I'll edit this post to add any relevant info that is requested for troubleshooting below.
-
Can you make a simple project, say, just a red rectangle in the center of a window and paste the code you created. If you aren't getting any errors from console, I would assume that there is something missing from the code, I have had projects that compile and show a white window with no content, only to realise I had not set 'visible: true' in ApplicationWindow.
I have also seen other posts where users say the same as you (a white window with no content showing) as they have made for example, Rectangle as the first module without an ApplicationWindow; i.e
import QtQuick 2.12 import QtQuick.Window 2.12 Rectangle { width: 320 height: 240 color: "red" anchors.centerIn: parent }
The above compiles without any error in console but nothing is shown
Where as this code when compiled does show content;
import QtQuick 2.12 import QtQuick.Window 2.12 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Rectangle { width: 320 height: 240 color: "red" anchors.centerIn: parent } }
Apologies if I am showing stuff you already know, but I can't think why no content would show otherwise.
Hope this helps.
-
Here are the steps I took to create this project:
- Created a new project selecting Qt Quick Application - Empty
- Selected qmake as Build System
- Set Minimal required Qt Version Qt 5.15
- Selected Desktop Qt 6.1.3 MinGW 64-bit as the Kit
- Replaced all code within main.qml with code from Markkyboy's post
Here's the output application running blank:
Note: Resizing the window to trigger a paint event does not cause the rectangle to showHere's the unchanged source code for 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(); }
Here's the source code for main.qml:
import QtQuick 2.12 import QtQuick.Window 2.12 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Rectangle { width: 320 height: 240 color: "red" anchors.centerIn: parent } }
To be honest the only thing I can think to do at this point is to uninstall and install fresh but that seems like a pain so I'd rather not. I feel like the issue must be systemic since it also occurs with Qt's included example projects.
@Markkyboy said in Projects with QML Compile Blank:
Apologies if I am showing stuff you already know, but I can't think why no content would show otherwise.
No worries, it's good to get the obvious out of the way. I only have a passing knowledge of QML at this point (due to lack of ability to play with it lol) so all help is appreciated.
-
Well, I decided to try a fresh install and encountered several errors similar to these:
The errors came in pairs and all followed the format of "Running qmake resulted in a crash" and "Couldn't find the output needed from qmake"
Doing so reminded me of a similar set of errors that I ignored on my first installation of Qt Creator, meaning this was always a problem.
Looking into these errors led me to a bug report of another user having the same issue with installation:
https://bugreports.qt.io/browse/QTBUG-94779In the comments I saw
Hi, just noticed you are trying to install using Windows 7. Windows 7 isn't supported development host for Qt6, see https://www.qt.io/blog/qt6-development-hosts-and-targets. See also https://doc.qt.io/qt-6/supported-platforms.html
And there's my issue. I'm running a windows 7 machine so I have to assume my issue is somehow related to that.
Anyway I completed the installation by ignoring all the errors that came up and now Qt Creator won't even start, whoops!
At this point I guess I can call this solved??
-
I am also running Windows 7, but not QT6, I think may be the problem, QT6 seems not to be quite ready for public use, modules are missing/removed/buggy/incomplete.
I am running QtCreator 5.0.3 based on Qt5.15.2. My apologies, I should have read your reply more thoroughly, then I would have noticed you're using QT6.......i think this is where the real problem is.