Qt World Summit: Register Today!

[solved]QQmlcomponent:component is not ready

  • i want to use QML object on C++ by these codes :
    // Using QQmlComponent

    QQmlEngine engine;
    QQmlComponent component(&engine,
    QObject *object = component.create();
    delete object;

    (from QT help )

    but get this mesage : QQmlcomponent:component is not ready

    when write a wrong address insted of MyItem.qml (use a address dos not exist) i get that too !
    i thing my Qml file is not accessable .
    please help me .

  • Moderators

    Hi @mahadin and welcome,
    That error is thrown when the qml if not found as you said and also thrown even if there is an error in qml file. So check the accessibility of file first and for errors if any in the file.

  • @p3c0
    I use a empty QML file like :

    import QtQuick 2.0

    Rectangle {
    width: 100
    height: 62

    i have this problem with example code in QT help.
    how can I check the accessibility of QML file ?

  • Moderators

    @mahadin Ok. The QML file looks good. Since you are using QUrl::fromLocalFile("MyItem.qml")) it means the file should present in the current working directory of the project. Either Check it manually by hand or use QFiles exist method to check the file.

    QFile file("MyItem.qml");

  • I cheked it manually !
    it persent in direcrory that my .pro and main.cpp files is there . :(

  • Moderators

    @mahadin OK. What does file.exists() show ?

  • @p3c0
    i cheke it by these codes :

    QFile file("MyItem.qml");
    if (file.exists())msg.setText("exist");
        else msg.setText("False");

    it return False ! :(
    ََ@p3c0 Tanks 4 your asnwers ! :)

  • Moderators

    @mahadin Hmm, I guess the problem must be that the qml file is not present in the compiled executable's current working directory. Try giving a complete path of qml file instead.
    Or you can add it in your qrc file and load it from there as follows:

    QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/MyItem.qml")))

  • @p3c0
    so taaaaaaaaaaanks :)
    my problem solved ... :D

    ممنون . خدا خیرتان دهد !

Log in to reply