Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]I cant use qrc files in my project
QtWS25 Last Chance

[solved]I cant use qrc files in my project

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.7k Views
  • 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.
  • mahadinM Offline
    mahadinM Offline
    mahadin
    wrote on last edited by mahadin
    #1

    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 )

    p3c0P 1 Reply Last reply
    0
    • mahadinM 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 )

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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
      0
      • mahadinM Offline
        mahadinM Offline
        mahadin
        wrote on last edited by mahadin
        #3

        @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 :(

        p3c0P 1 Reply Last reply
        0
        • mahadinM 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 :(

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

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

          157

          1 Reply Last reply
          0
          • mahadinM Offline
            mahadinM Offline
            mahadin
            wrote on last edited by mahadin
            #5

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

            p3c0P 1 Reply Last reply
            0
            • mahadinM mahadin

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

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @mahadin Did you specify QUrl ?

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

              157

              1 Reply Last reply
              0
              • mahadinM Offline
                mahadinM Offline
                mahadin
                wrote on last edited by mahadin
                #7

                @p3c0
                it work correctly by useing QUrl ;

                tanks :)

                p3c0P 1 Reply Last reply
                0
                • mahadinM mahadin

                  @p3c0
                  it work correctly by useing QUrl ;

                  tanks :)

                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @mahadin Great. Happy Coding ...

                  157

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved