I use Qt 5.5.0 MSVC 2013, 32bit.
I want to create minimal QtQuick application. When I choose New Project - Qt Quick Application I got project with 2 QML files: main.qml and MainForm.ui.qml. Since I do not need them, I delete second one and paste following to main.qml:
Import QtQuick 2.4
Rectangle{
id: root
visible: true
color: "gray"
width: 400
height: 800
}
But when I run project I got nothing. I see application in Task Manager but there is no application window.
Question: Is it possible to create .qml file with Rectangle as a root element?
Solution was found at official Qt Forum.
The template for creating Qt Quick Application adds QQmlApplicationEngine to launch the QML. But QQmlApplicationEngine dont work directly with Rectangle or Item as root element but requires any window like Window or ApplicationWindow.
So to make it work for Rectangle use QQuickView instead of QQmlApplicationEngine.
I changed content of main.cpp to
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickView *view = new QQuickView;
view->setSource(QUrl("qrc:/main.qml"));
view->show();
return app.exec();
}
and it solved my problem.
Related
WebEngineView should be displayed in the whole window, but it's not. Right margin strip and bottom margin strip is not displayed. Instead a strip of (red) background is visible. Yet I can click on red background on the input search formular and it can be filled. There shouldnt be any background visible.
I also tried QWebEngineView instead of QQmlApplicationEngine and it is exactly the same.
This code is run by Qt 6.4.0.
In Qt 5.12.5 it is displayed correctly.
What to do to show WebEngineView in the whole window ?
main.cpp:
int main(int argc, char *argv[])
{
QtWebEngineQuick::initialize();
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/webengine.qml")));
return app.exec();
}
webengine.qml:
import QtQuick
import QtQuick.Window
import QtWebEngine
Window {
width: 800
height: 600
visible: true
color: "red"
WebEngineView {
id: webEngineView
anchors.fill: parent
url: "https://doc.qt.io/qt-6/qtwebengine-webenginequick-minimal-example.html"
}
}
The gui:
This should already be fixed in 6.4.0, was this observed during the beta, if so, then try with the final release. If observed with the final, please open a bug report for at Qt.
I am using Qt Quick Application project in QT 5.2.1 in Linux Mint 13 and I want use relative path to my audio files, which are located in sounds folder of my project folder.
Here is my
main.qml
import QtQuick 2.2
import QtQuick.Window 2.1
import QtMultimedia 5.0
Window {
visible: true
width: 360
height: 360
Audio{
id: sound
source: "sounds/1.mp3" //doesn't work
source: "file:../sounds/1.mp3" //also doesn't work
source: "file:/home/vlado/Qt projects/test521/sounds/1.mp3" //this works
}
MouseArea {
anchors.fill: parent
onClicked: {
sound.play()
}
}
Text {
text: qsTr("Play Sound")
anchors.centerIn: parent
}
}
Doesn't work means, that there is following error:
GStreamer; Unable to play - "" Error: "No URI set"
As you can see, everything is OK, if I use absolute path, but I would like to deploy this application and installation folder then will be different. That's why I want to use relative path.
Here is my
test521.pro
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
Here is
my main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
return app.exec();
}
How to set relative path instead of absolute?
Edit: Solution for QML: how to specify image file path relative to application folder doesn't work for me.
Why is a TextArea with
wrapMode: TextEdit.NoWrap
always causing
file:///C:/Qt/5.5/mingw492_32/qml/QtQuick/Controls/ScrollView.qml:340:13: QML Item: Possible anchor loop detected on fill.
when I run it?
I am running Qt 5.5 on a 64-bit Windows 7 machine, and compiling with MinGW.
Here is my QML code test.qml:
import QtQuick 2.4
import QtQuick.Controls 1.3
ApplicationWindow {
title: "test window"
width: 500
height: 500
visible: true
TextArea {
wrapMode: TextEdit.NoWrap
}
}
Here is my C++ code main.c:
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/test.qml")));
return app.exec();
}
Even if I add anchors.fill: parent to the TextArea, I still get the warnings.
As a second part of this question, is this warning something I should be worried about, or is it something I can safely ignore?
I think it's a bug from Qt, you can ignore it.
When created, TextArea have a width != 0, even if it's empty. When you enter a text that have an implicitWidth smaller then the (default) width of the TextArea, you will get this warning.
A workaround is to assign the wrapMode property in the Component.onCompleted handler:
Component.onCompleted: wrapMode = TextEdit.NoWrap
I've experienced a strange problem: when a QML Window is fullscreen, its opacity property doesn't work, so the window stay opaque. When the window isn't fullscreen (e.g. maximized), it works properly.
Do you have any ideas how to deal with this problem?
In fact, I want to animate fullscreen window fading in.
The code:
main.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.1
Window {
visible: true
visibility: "FullScreen"
opacity: 0.5
Text {
id: text
text: "Hello World"
font.pointSize: 36
color: "#333"
}
}
main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
I use Qt 5.3 on Windows 8.1.
This is the age-old bug of the Qt/Win combination - windows with an OpenGL context, can't be made transparent without employing trickery. The solution is to embed your QML application in a QQuickWidget and make that transparent and full-screen. There also exists another workaround (using the 'DWM' API, which is nonportable - you can read about it in the bug description).
https://bugreports.qt.io/browse/QTBUG-28214
I have created qml/test.qml file as:
import QtQuick 1.0
Rectangle
{
id: pahe
width: 200; height: 50
color: "#55aaee"
TextInput
{
id: editor
anchors
{
left: parent.left; right: parent.right; leftMargin: 10; rightMargin: 10
verticalCenter: parent.verticalCenter
}
cursorVisible: true;
font.bold: true
color: "#151515";
selectionColor: "Green"
focus: true
}
}
and One qml/main.cpp file as:
#include <QApplication>
#include <QtDeclarative>
#include <QDeclarativeView>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("test.qml"));
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.show();
return app.exec();
}
I am compiling this main.cpp file using commands like:
#qmake -project
#qmake
#make
and I am running the exe as:
./qml
So problem is that I am not able to see any text on TextInput even after entering text using key board. If i print the TextInput.text of element it shows entered text on console log but can not see on screen.
What could be the reason?
If i run same test.qml file using qmlviewer it works fine.
Any hint or comment in this would be helpful.
Thanks,
KBalar
why don't you try simulator? U said, it as an exe and why r u running it in a Linux style "./". If you still have the problem, check the background of the Rectangle or TextEdit and the font color.
The problem was with virtual Linux machine running on Windows PC. So If i run same example on Real Linux machine The problem wont be there.