Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved]I cant use qrc files in my project

    General and Desktop
    2
    8
    2300
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mahadin
      mahadin last edited by mahadin

      hi .
      i make a text file and write this code on it :

      <!DOCTYPE RCC><RCC version="1.0">
      <qresource>
      <file>qml.qml</file>
      </qresource>
      </RCC>

      and save it as a qrc file .
      whene i add this qrc file to my project qmlf.qrc and that .qml file are shown .
      but whene i use it in my code it not work .

      QFile file("qrc:/qml.qml");
      if (file.exists())msg.setText("exist");
          else msg.setText("False");
      msg.exec();
      

      and return false .

      (i use minGw and I have this proble whene use short path of file and I have to write complate path of files that i want to use even that file exist in my current )

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @mahadin last edited by

        @mahadin Try :/qml.qml instead of qrc:/qml.qml. Also you can create qrc file from QtCreator itself instead of doing it manually.
        Project > Add New > Qt > Qt Resource File

        157

        1 Reply Last reply Reply Quote 0
        • mahadin
          mahadin last edited by mahadin

          @p3c0
          its amazing!
          QFile work OK!

          QFile file(":/qml.qml");
          if (file.exists())msg.setText("exist");
              else msg.setText("False");
          msg.exec();
          

          return exist

          but QQmlComponent no !

          QQmlEngine engine;
          QQmlComponent component(&engine,":/qml.qml");
          
          QObject *object = component.create();
          

          it return :
          QQmlComponent: Component is not ready :(

          p3c0 1 Reply Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators @mahadin last edited by

            @mahadin Here you need to use qrc:/qml.qml.

            157

            1 Reply Last reply Reply Quote 0
            • mahadin
              mahadin last edited by mahadin

              @p3c0
              i test "qrc:/qml.qml"
              it doesnt work! :|

              p3c0 1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators @mahadin last edited by

                @mahadin Did you specify QUrl ?

                QQmlEngine engine;
                QQmlComponent component(&engine,QUrl("qrc:/qml.qml"));
                

                157

                1 Reply Last reply Reply Quote 0
                • mahadin
                  mahadin last edited by mahadin

                  @p3c0
                  it work correctly by useing QUrl ;

                  tanks :)

                  p3c0 1 Reply Last reply Reply Quote 0
                  • p3c0
                    p3c0 Moderators @mahadin last edited by

                    @mahadin Great. Happy Coding ...

                    157

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post