Errors while loading Qt include files
-
Hi,
i have a problem in a project where i want to mix Qt/C++ and QML. I don't know why but Qt Creator tell me that there is 39 problems in different Qt include files (sorry i didn't find how to put it in English) :
So, as you can see, errors got an encoding problem and it seems unlogic. It happens since i try to adaptate my Line class to pass it by context property to my Qml.
This is my .pro file :
QT += quick quickcontrols2 core CONFIG += c++11 # 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 += \ entite.cpp \ ligne.cpp \ main.cpp RESOURCES += qml.qrc \ icons/index.theme \ icons/20x20/back.png \ icons/20x20/drawer.png \ icons/20x20/menu.png \ icons/20x20@2/back.png \ icons/20x20@2/drawer.png \ icons/20x20@2/menu.png \ icons/20x20@3/back.png \ icons/20x20@3/drawer.png \ icons/20x20@3/menu.png \ icons/20x20@4/back.png \ icons/20x20@4/drawer.png \ icons/20x20@4/menu.png \ # 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 += \ entite.h \ ligne.h
The Line class (.h) :
#ifndef LIGNE_H #define LIGNE_H #include <QObject> #include <QVector> #include <QVariant> #include <time.h> #include "entite.h" class Ligne : public QObject { Q_OBJECT Q_PROPERTY(QString name READ getName CONSTANT) Q_PROPERTY(QVector<QVariant> inTab READ getIn CONSTANT) Q_PROPERTY(QVector<QVariant> outTab READ getOut CONSTANT) private: QVector<QVariant> inTab; QVector<QVariant> outTab; QString name; public: Ligne(QString,int,int); Ligne(const Ligne&); inline QList<QVariant> getIn() { return QVariantList::fromVector(inTab);} inline QList<QVariant> getOut() {return QVariantList::fromVector(outTab);} inline QString getName() { return name;} inline QVariant getIn(int index) { return inTab.at(index);} inline QVariant getOut(int index) { return outTab.at(index);} inline void addIn(QString name, int value) {inTab.push_back(QVariant::fromValue(entite(name,value)));} inline void addOut(QString name, int value) {outTab.push_back(QVariant::fromValue(entite(name,value)));} }; Q_DECLARE_METATYPE(Ligne) #endif // LIGNE_H
The Line class (.cpp) :
#include "ligne.h" Ligne::Ligne(QString _name, int nbIn, int nbOut) { name = _name; srand( (unsigned)time(NULL) ); for(int i=0; i<nbIn;i++) addIn(QString("Entree "+QString::number(i+1)),int(rand() % 2)); for(int i=0; i<nbOut;i++) addOut(QString("Sortie "+QString::number(i+1)),int(rand() % 2)); } Ligne::Ligne(const Ligne& _ligne) { name = _ligne.name; inTab = _ligne.inTab; outTab = _ligne.outTab; }
And in conclusion my main.cpp :
#include <QGuiApplication> #include <QtQml> #include <QSettings> #include <QQmlContext> #include <QQuickStyle> #include <QIcon> #include "ligne.h" 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); QIcon::setThemeName("gallery"); QSettings settings; if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) QQuickStyle::setStyle(settings.value("style").toString()); const QString styleInSettings = settings.value("style").toString(); if (styleInSettings.isEmpty()) settings.setValue(QLatin1String("style"), QQuickStyle::name()); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/Main.qml")); QStringList builtInStyles = { QLatin1String("Basic"), QLatin1String("Fusion"), QLatin1String("Imagine"), QLatin1String("Material"), QLatin1String("Universal") }; #if defined(Q_OS_MACOS) builtInStyles << QLatin1String("macOS"); #elif defined(Q_OS_WINDOWS) builtInStyles << QLatin1String("Windows"); #endif QVariantList datalist = { QVariant::fromValue(Ligne(QString("Test 1"),10,10)), QVariant::fromValue(Ligne(QString("Test 2"),10,10)), QVariant::fromValue(Ligne(QString("Test 3"),10,10)), QVariant::fromValue(Ligne(QString("Test 4"),10,10)) }; engine.setInitialProperties({{ "builtInStyles", builtInStyles }}); engine.rootContext()->setContextProperty("dataModel", datalist); 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(); }
Someone got an idea of my problem please ? :)
-
You are right, it seems the problem come from my copy constructor which i can't do because of the inheritance of QObject. So i replaced it by QGadget and it works well (I also created a new project to begin on clean base). Thanks a lot !
-
Hi and welcome to devnet,
Your RESOURCES variable content looks wrong.
It should be a list of .qrc files unless I missed something in the latest versions.
You also have one backslash at the end of the last entry and you should not.
-
Hi, thanks for your answer, i removed the backslash but it changed nothing. :'(
Regarding my resources, i have one qrc file which list each of my qml file :
isn't it correct ?
-
@Pierre-Castor said in Errors while loading Qt include files:
Someone got an idea of my problem please ? :)
I think the problem is that you
Ligne
class do not have any default/copy constructor and so cannot be used in a list. -
You are right, it seems the problem come from my copy constructor which i can't do because of the inheritance of QObject. So i replaced it by QGadget and it works well (I also created a new project to begin on clean base). Thanks a lot !