Harrix
Harrix

Reputation: 547

Program with qml in resource file don’t open non-main qml files

I installed Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)

Then I created simple Quick 2 application. I have two simple qml files:

main.qml

import QtQuick 2.0

Rectangle {
    width: 360
    height: 360
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    HarrixMainButton{

    }
}

HarrixMainButton.qml

import QtQuick 2.0

Item {
    width: 93
    height: 93

    Rectangle {
        width: 50
        height: 62
        color: "red"
    }

}

And the program is working well. Then I put the qml files into the resource res.qrc in prefix qml and change main.cpp:

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QUrl>
#include <QDebug>
#include <QQmlContext>
#include <QQuickItem>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    //viewer.setMainQmlFile(QStringLiteral("qml/HarrixAI/main.qml"));
    viewer.setSource(QUrl("qrc:qml/qml/HarrixAI/main.qml"));
    viewer.showExpanded();

    return app.exec();
}

And the program does not work. The second file HarrixMainButton.qml is not loaded. Only the main first file main.qml is loaded.

qrc:qml/qml/HarrixAI/main.qml:16:5: HarrixMainButton is not a type Unable to find a renderable master window QtQuick2ApplicationViewer(0x28fe08) when trying to render QtQuick2ApplicationViewer(0x28fe08) ( QRect(8,30 116x0) ).

How to fix the problem? In Qt 4.7 with Qt Quick 1.1 same method works.

Upvotes: 2

Views: 2997

Answers (1)

Eskil
Eskil

Reputation: 86

Don't use relative paths in the URL when loading main.qml and it should work:

https://bugreports.qt-project.org/browse/QTBUG-26417

Upvotes: 1

Related Questions