I want to compile and run WebEngine Recipe Browser Example with Qt-6.2.3 or Qt_6_4_0 but I get this error:
QML debugging is enabled. Only use this in a safe environment.
qt.webenginecontext:
GLImplementation: desktop
Surface Type: OpenGL
Surface Profile: CompatibilityProfile
Surface Version: 4.6
Using Default SG Backend: yes
Using Software Dynamic GL: no
Using Angle: no
Init Parameters:
* application-name recipebrowser
* browser-subprocess-path /home/parisa/Applications/Qt/6.2.3/gcc_64/libexec/QtWebEngineProcess
* create-default-gl-context
* disable-features DnsOverHttpsUpgrade,ConsolidatedMovementXY,InstalledApp,BackgroundFetch,WebOTP,WebPayments,WebUSB,PictureInPicture
* disable-setuid-sandbox
* disable-speech-api
* enable-features NetworkServiceInProcess,TracingServiceInProcess
* enable-threaded-compositing
* gpu-preferences UAAAAAAAAAAoAAAQAAAAAAAAAAAAAAAAAABgAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAACAAAAAAAAAA=
* in-process-gpu
* use-gl desktop
and I see this result:
web pages (html content ) can't load from qrc (Resource file).
But as I Build and Run this example in Qt-5.15.2 it runs correctly.
The only difference between these two versions and examples is that Qt-5.15.2 uses QtWebEngine but in Qt-6.2.3 or Qt_6_4_0 they use QtWebEngineQuick.
I dont know how should I fix this issue and use QtWebEngineQuick.
I test QtWebEngineQuick and this issue will happen when I want to load any HTML file (even simple) from Resource , but if I choose url from web like https://stackoverflow.com it works correctly.
for example, if I want to Run this Example I got that Error!
in main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtWebEngineQuick/qtwebenginequickglobal.h>
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QtWebEngineQuick::initialize();
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();
}
in main.qml
import QtQuick
import QtQuick.Window
import QtWebEngine
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
WebEngineView {
id: webView
anchors.fill: parent
url: "qrc:/index.html"
}
}
in index.html
<html>
<head>
</head>
<body>
<h1>Hello World<h1>
</body>
</html>
error output picture:
I use Ubuntu 20.04 and NVIDIA 470 GPU.
I don't understand why this happens and how can I fix it.
Related
I want get json file from local and send it to QML using this:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
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"));
engine.rootContext()->setContextProperty("text_json", "{\"text1\": \"Loading\"}");
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();
}
But it say that QQmlEngine::setContextForObject(): Object already has a QQmlContext but I don't understand anything from that default file.
I don't have found anything from now.
-- Added Main.qml --
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
id: window
width: 640
height: 480
visible: true
title: qsTr("Stack")
property var text_json: ({"text1": "Loading"})
header: ToolBar {
contentHeight: toolButton.implicitHeight
ToolButton {
id: toolButton
icon.source: "./images/ruby.png"
font.pixelSize: Qt.application.font.pixelSize * 1.6
onClicked: {
drawer.open()
}
}
Label {
text: stackView.currentItem.title
anchors.centerIn: parent
}
}
}
Maybe a bit late, but did you try importing in your Main.qml without version number?
import QtQuick
import QtQuick.Controls
In my Qt Quick Application, I wanna use Qt.createComponent to create component dynamically——the effect I expect: when I click the button"create checkbox" ,the window will create a CheckBox dymamically
I made it in a Qt Quick UI prototype(qml-only project),but failed in the Qt Quick Application
After running the app, I click the button"create checkbox" many times, but the window has no response and the program stuck
// app.pro
QT += quick
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#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
//main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
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();
}
// CheckBox.qml
import QtQuick 2.0
import QtQuick.Controls 2.12
CheckBox{
text: "checkcheck"
}
//main.qml
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
id:root
visible: true
width: 200
height: 200
title: qsTr("Hello World")
Button{
text: "create checkbox"
anchors.centerIn:parent
onClicked: loadCheckBox(root)
}
function loadCheckBox(parent){
var obj=Qt.createComponent("CheckBox.qml");
if(obj.status==Component.Ready){
var checkBox=obj.createObject(parent)
}
}
}
My environment: Win10 QtCreator Qt5.13.2_MSVC2017_64bit
Anyone knows how to modify it?
I try to register my custom CPP Class in QML with Qt5.15.0 and the new macro QML_ELEMENT, but the Module is not found. The Qt Creater help files describes the steps for the QML_ELEMENT. I checked the Qt Manual too, but without happy end (https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html).
//testclass.h
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <QObject>
#include <QtQml>
class testclass : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit testclass(QObject *parent = nullptr);
signals:
};
#endif // TESTCLASS_H
// testclass.cpp
#include "testclass.h"
testclass::testclass(QObject *parent) : QObject(parent)
{
}
The pro file looks like this:
QT += quick
CONFIG += c++11
CONFIG += qmltypes
QML_IMPORT_NAME = com.mycompany.test
QML_IMPORT_MAJOR_VERSION = 1
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
testclass.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
HEADERS += \
testclass.h
The Metafile gets generated with this content:
[
{
"classes": [
{
"classInfos": [
{
"name": "QML.Element",
"value": "auto"
}
],
"className": "testclass",
"object": true,
"qualifiedClassName": "testclass",
"superClasses": [
{
"access": "public",
"name": "QObject"
}
]
}
],
"inputFile": "testclass.h",
"outputRevision": 67
}
]
And afterwards I try to use this class in my Main.qml, but Qt Creator shows QML Module not found.
// main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import com.mycompany.test 1.0 // QML Module not found
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
//Main.cpp
#include "testclass.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
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();
}
Did I missed something or is it buggy?
** Edit **
I refactored the Classname from testclass to Testclass, but still I get the same error. Of Course I made Clean and rebuild. I'm using Windows 10, MinGw-64Bit and qmake.
//testclass.h
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <QObject>
#include <QtQml>
class Testclass : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit Testclass(QObject *parent = nullptr);
signals:
};
#endif // TESTCLASS_H
//testclass.cpp
#include "testclass.h"
Testclass::Testclass(QObject *parent) : QObject(parent)
{
}
// Metafile
[
{
"classes": [
{
"classInfos": [
{
"name": "QML.Element",
"value": "auto"
}
],
"className": "Testclass",
"object": true,
"qualifiedClassName": "Testclass",
"superClasses": [
{
"access": "public",
"name": "QObject"
}
]
}
],
"inputFile": "testclass.h",
"outputRevision": 67
}
]
//main.cpp
#include "testclass.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
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();
}
//main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import com.mycompany.test 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
I got the same error with the example code trying to build it with MinGW. But the strange thing is that the same code works flawless after compiling for Android with Clang multi-Abi.
you could try using the older methode of doing this from QT 5.9 https://doc.qt.io/qt-5.9/qtqml-cppintegration-topic.html
you just need to add this in you main.cpp and include your Testclass header
qmlRegisterType<Testclass>("com.mycompany.test", 1, 0, "Testclass")
Although I don't get that error if I get the following warning:
Invalid QML element name "testclass"; type names must begin with an uppercase letter
And since when using QML_ELEMENT the name of the class is taking as the name of the item and the QML rules the names of the items must start with capital letters so it causes an error. The solution is to change the class name from testclass to Testclass, then recompile (it may be necessary to remove the build folder).
I've taken all care to disable the ANGLE layer in my Qt app, but apparently it's not happening. When I run the app in the CodeXL debugger, the event log contains lines like:
DLL Loaded: C:\Windows\SysWOW64\d3d11.dll
So it's loading Direct3D, which in Qt only happens via ANGLE I think. Also hitting the "Break" button in CodeXL does nothing, which to me means that no real OpenGL calls are happening, they're getting translated to D3D only.
The event log also says this:
Debug String: Failed to load opengl32.dll (The specified module could not be found.)
Why might that happen, how can I fix it?
The reason I want to disable ANGLE is because otherwise I can't debug with CodeXL (it doesn't support D3D debugging).
My system:
Windows 10
First GPU: Intel HD Graphics 5500
Second GPU: AMD Radeon R5 M330 (I think this is the one my app uses)
My code:
main.cpp:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickFramebufferObject>
#include <QOpenGLShaderProgram>
#include <QOpenGLFramebufferObject>
#include <QQuickWindow>
class MyItem : public QQuickFramebufferObject {
Q_OBJECT
public:
Renderer* createRenderer() const;
};
class MyItemRenderer : public QQuickFramebufferObject::Renderer {
public:
void render() {
update();
}
QOpenGLFramebufferObject* createFramebufferObject(const QSize &size) {
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
return new QOpenGLFramebufferObject(size, format);
}
};
QQuickFramebufferObject::Renderer* MyItem::createRenderer() const {
return new MyItemRenderer();
}
int main(int argc, char **argv) {
qputenv("QT_OPENGL_BUGLIST", "Z:/disable_angle.txt");
QGuiApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
QGuiApplication app(argc, argv);
qmlRegisterType<MyItem>("MyItem", 1, 0, "MyItem");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
#include "main.moc"
main.qml:
import QtQuick 2.0
import MyItem 1.0
import QtQuick.Window 2.2
Window {
visible: true
width: 400
height: 400
MyItem {
anchors.fill: parent
}
}
Z:/disable_angle.txt:
{
"entries": [
{
"id": 1,
"description": "Disable angle",
"os": {
"type": "win"
},
"features": [
"disable_angle"
]
}
]
}
Set QT_LOGGING_RULES environment variable to 'qt.qpa.gl=true'. Thus, you will see some additional debug output that will help to understand what exactly Qt chooses (opengl/angle/software).
Try changing Z:/disable_angle.txt to Z:\disable_angle.txt
Note the backslash :) It's Windows, so this may be the culprit.
Apart from disable_angle (your config seems correct to me), try also setting disable_d3d11 and disable_d3d9.
"disable_angle", "disable_d3d11", "disable_d3d9"
If you want to completely disable Angle, you should set the application attribute Qt::AA_UseDesktopOpenGL. If this is not enough, linking against OpenGL32.lib might help.
When I try to import the QtCharts module to my QML files y always get the same warning message:
"found not working imports: file: C:/.... module "QtCharts" is not
installed"
I'm using OpenSource QtCreator 4.0.3 with Qt 5.7.0.
I have the folder QtCharts in the path: C:\Qt\5.7\mingw53_32\qml
I've also included the folder path using the property in the .pro file:
QML2_IMPORT_PATH: C:\Qt\5.7\mingw53_32\qml
What am I missing?
Here is a simple test code:
// QtChartsTest.pro
TEMPLATE = app
QT += qml quick
QT += charts
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML2_IMPORT_PATH = C:\Qt\5.7\mingw53_32\qml
# Default rules for deployment.
include(deployment.pri)
// Main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
// Main.qml
import QtQuick 2.7
import QtQuick.Window 2.2
import QtCharts 2.1
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
}
I was stuck on a similar issue and was frustrated by Qt's documentation on the subject, so I'll put my method of solving my own issues here for posterity.
I'm not sure of the exact cause of your issue, but I can offer you a suggestion to try and troubleshoot it.
In your main.cpp add the following line.
qDebug()<<engine.importPathList();
So your main will be
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDebug>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
qDebug()<<engine.importPathList();
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
This will include the complete list of include paths. If you do not see the include path listed there you can add it by adding the following line:
engine.addImportPath(directory);
where "directory" is a QString to the include directory.
My understanding is that the QML2_IMPORT_PATH variable only applies at run time, and not at compile time, which means that QtCreator does not see the path when it compiles. engine.addImportPath(directory); on the other hand adds the path prior to starting the qml engine, (and thus the first qml import statements)
I am not saying this is the best way to solve your issue, but it did help me solve my issue.
int main(int argc, char *argv[])
{
// Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used.
QApplication app(argc, argv);
QQuickView viewer;
// The following are needed to make examples run without having to install the module
// in desktop environments.
#ifdef Q_OS_WIN
QString extraImportPath(QStringLiteral("%1/../../../../%2"));
#else
QString extraImportPath(QStringLiteral("%1/../../../%2"));
#endif
viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(),
QString::fromLatin1("qml")));
//***** [Solve] FORCE THE MODULE TO BE IMPORTED.
QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
qDebug() << viewer.engine()->importPathList();
viewer.setTitle(QStringLiteral("QML Axes"));
viewer.setSource(QUrl("qrc:/qml/qmlaxes/main.qml"));
viewer.setResizeMode(QQuickView::SizeRootObjectToView);
viewer.show();
return app.exec();
}
[Output through qDebug()]
("/home/snjee/workspace_qt/maxelecPrjs/build-maxCoffeeTdsMeterApp-Desktop_Qt_5_15_2_GCC_64bit-Debug", "qrc:/qt-project.org/imports", "/opt/Qt/5.15.2/gcc_64/qml")
You can find the answer in the built-in "QML Axes" example source.