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]can't open file from qresources

[SOLVED]can't open file from qresources

Scheduled Pinned Locked Moved General and Desktop
ressource
23 Posts 4 Posters 8.8k 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.
  • H Offline
    H Offline
    Hamed
    wrote on 18 Apr 2015, 17:41 last edited by Hamed
    #1

    Hi.
    I can't open a file that I added to my .qrc file.
    here is my .qrc file :
    <RCC>
    <qresource prefix="/plane">
    <file>j3pipercub.obj</file>
    </qresource>
    </RCC>

    and this is how I call this file :
    mesh = load_object(":/plane/j3pipercub.obj");

    HamedBabaeyan@yahoo.com
    for more interesting stuff

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 18 Apr 2015, 17:43 last edited by
      #2

      Hi,
      did you add the resouce file to your project file?

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hamed
        wrote on 18 Apr 2015, 17:44 last edited by
        #3

        yes this is how I did that :
        RESOURCES = mresources.qrc

        HamedBabaeyan@yahoo.com
        for more interesting stuff

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 18 Apr 2015, 17:48 last edited by
          #4

          Any errors or warnings when building the project?

          1 Reply Last reply
          1
          • H Offline
            H Offline
            Hamed
            wrote on 18 Apr 2015, 17:50 last edited by
            #5

            No, It just not load that .obj file.
            I can load it by address in my pc but can't load it from resources.

            HamedBabaeyan@yahoo.com
            for more interesting stuff

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 18 Apr 2015, 17:52 last edited by
              #6

              Did you try removing the build directory and doing a complete rebuild?

              1 Reply Last reply
              1
              • H Offline
                H Offline
                Hamed
                wrote on 18 Apr 2015, 17:54 last edited by
                #7

                No, I try it now.

                HamedBabaeyan@yahoo.com
                for more interesting stuff

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hamed
                  wrote on 18 Apr 2015, 17:59 last edited by
                  #8

                  Did it.
                  Still doesn't work!

                  HamedBabaeyan@yahoo.com
                  for more interesting stuff

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on 18 Apr 2015, 18:10 last edited by
                    #9

                    Can you give me a copy of that file so I can try it?

                    1 Reply Last reply
                    1
                    • H Offline
                      H Offline
                      Hamed
                      wrote on 18 Apr 2015, 18:12 last edited by
                      #10

                      sure, how can I do that?

                      HamedBabaeyan@yahoo.com
                      for more interesting stuff

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on 18 Apr 2015, 18:39 last edited by
                        #11

                        The file works for me. Please try this in your load_object() function:

                            QFile file(":/plane/j3pipercub.obj");
                            if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
                                qDebug() << "file read error";
                                return;
                            }
                            const QByteArray ba = file.readAll();
                            file.close();
                            const QString s( ba );
                            qDebug() << s;
                        
                        1 Reply Last reply
                        1
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on 18 Apr 2015, 19:17 last edited by
                          #12

                          Ok, let's see if we can copy the file's content to another file:

                              QFile file(":/plane/j3pipercub.obj");
                              if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
                                  qDebug() << "file read error";
                                  return;
                              }
                              const QByteArray ba = file.readAll();
                              file.close();
                          
                              QFile file2("/home/pw/piper.obj"); // +++++ ADJUST PATH ++++++
                              if (!file2.open(QIODevice::WriteOnly)) {
                                  qDebug() << "file write error";
                                  return;
                              }
                              qDebug() << file2.write(ba);
                              file2.close();
                          
                          1 Reply Last reply
                          1
                          • M Offline
                            M Offline
                            mcosta
                            wrote on 18 Apr 2015, 19:21 last edited by
                            #13

                            HI,

                            have you used Q_INIT_RESOURCE to initialize the resource??

                            Once your problem is solved don't forget to:

                            • Mark the thread as SOLVED using the Topic Tool menu
                            • Vote up the answer(s) that helped you to solve the issue

                            You can embed images using (http://imgur.com/) or (http://postimage.org/)

                            1 Reply Last reply
                            1
                            • H Offline
                              H Offline
                              Hamed
                              wrote on 18 Apr 2015, 19:22 last edited by
                              #14

                              No! where should I initialize it?

                              HamedBabaeyan@yahoo.com
                              for more interesting stuff

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mcosta
                                wrote on 18 Apr 2015, 19:24 last edited by
                                #15

                                Hi,

                                in the main(); something like

                                int main (int argc, char *argv[])
                                {
                                    QApplication app(argc, argv);
                                
                                    Q_INIT_RESOURCE(mresources);
                                
                                    .....
                                }
                                

                                Once your problem is solved don't forget to:

                                • Mark the thread as SOLVED using the Topic Tool menu
                                • Vote up the answer(s) that helped you to solve the issue

                                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                                ? 1 Reply Last reply 18 Apr 2015, 19:27
                                1
                                • M mcosta
                                  18 Apr 2015, 19:24

                                  Hi,

                                  in the main(); something like

                                  int main (int argc, char *argv[])
                                  {
                                      QApplication app(argc, argv);
                                  
                                      Q_INIT_RESOURCE(mresources);
                                  
                                      .....
                                  }
                                  
                                  ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on 18 Apr 2015, 19:27 last edited by
                                  #16

                                  @mcosta said:

                                  Q_INIT_RESOURCE

                                  Since when is this needed? Works for me without this.

                                  1 Reply Last reply
                                  1
                                  • H Offline
                                    H Offline
                                    Hamed
                                    wrote on 18 Apr 2015, 19:33 last edited by
                                    #17

                                    dear @mcosta it's not helped

                                    HamedBabaeyan@yahoo.com
                                    for more interesting stuff

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mcosta
                                      wrote on 18 Apr 2015, 19:34 last edited by
                                      #18

                                      @Wieland Q_INIT_RESOURCE is needed if the resource is not embedded in the application or on some platform

                                      Normally, when resources are built as part of the application, the resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro is necessary on some platforms for resources stored in a static library.

                                      Once your problem is solved don't forget to:

                                      • Mark the thread as SOLVED using the Topic Tool menu
                                      • Vote up the answer(s) that helped you to solve the issue

                                      You can embed images using (http://imgur.com/) or (http://postimage.org/)

                                      ? 1 Reply Last reply 18 Apr 2015, 19:36
                                      1
                                      • M mcosta
                                        18 Apr 2015, 19:34

                                        @Wieland Q_INIT_RESOURCE is needed if the resource is not embedded in the application or on some platform

                                        Normally, when resources are built as part of the application, the resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro is necessary on some platforms for resources stored in a static library.

                                        ? Offline
                                        ? Offline
                                        A Former User
                                        wrote on 18 Apr 2015, 19:36 last edited by A Former User
                                        #19

                                        @mcosta Things are a bit strange here. Reading from the resource works. In the code I posted above there is the bytearray ba and it has the correct size, but it contains only null bytes. But only on Hamed's computer! Works on mine. I don't get it.

                                        1 Reply Last reply
                                        1
                                        • M Offline
                                          M Offline
                                          mcosta
                                          wrote on 18 Apr 2015, 19:37 last edited by
                                          #20

                                          hi,

                                          so you could try to use an alias

                                          <RCC>
                                          <qresource prefix="/plane">
                                          <file alias="j3pipercub.obj">j3pipercub.obj</file>
                                          </qresource>
                                          </RCC>
                                          
                                          

                                          Once your problem is solved don't forget to:

                                          • Mark the thread as SOLVED using the Topic Tool menu
                                          • Vote up the answer(s) that helped you to solve the issue

                                          You can embed images using (http://imgur.com/) or (http://postimage.org/)

                                          ? 1 Reply Last reply 18 Apr 2015, 19:53
                                          1

                                          1/23

                                          18 Apr 2015, 17:41

                                          • Login

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