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. Open resource file
Forum Updated to NodeBB v4.3 + New Features

Open resource file

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 8.8k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    beowulf
    wrote on last edited by
    #1

    I have a file in my resource, I was wondering if is possible to run invisibly (not show the form).

    -- 0x00

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      I don't understand your question.

      If with "resource file" you mean a file that you have compiled into your binary using the "Qt Resource System":http://doc.qt.digia.com/qt/resources.html, it can be opened in a similar fashion to a local file by using QFile(":/filename.foo"). Alternatively, the data of the resource file can be accessed directly via memory pointer by using QResource(":/filename.foo").data(). With both ways the file won't be "visible" unless you make it visible.

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beowulf
        wrote on last edited by
        #3

        Yes, is Qt Resource System, but i don't want to read, i want to run.

        -- 0x00

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          Run WHAT ???

          If the file is an executable you cannot run it from the memory directly! Instead you will have to save it to a local file (e.g. in TEMP folder), then use QProcess to run the executable from the local path...

          @QString localPath = QString("%1/program.exe").arg(QDir::tempPath());

          QFile localFile(localPath);
          if(!localFile.open(QIODevice::WriteOnly))
          {
          qWarning("Oups!");
          return;
          }

          QResource resourceFile(":\program.exe");
          if(localFile.write(resourceFile.data(), resourceFile.size()) != resourceFile.size())
          {
          qWarning("Oups!");
          return;
          }
          localFile.close();

          QProcess::execute(localPath);@

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          M 1 Reply Last reply
          0
          • M MuldeR

            Run WHAT ???

            If the file is an executable you cannot run it from the memory directly! Instead you will have to save it to a local file (e.g. in TEMP folder), then use QProcess to run the executable from the local path...

            @QString localPath = QString("%1/program.exe").arg(QDir::tempPath());

            QFile localFile(localPath);
            if(!localFile.open(QIODevice::WriteOnly))
            {
            qWarning("Oups!");
            return;
            }

            QResource resourceFile(":\program.exe");
            if(localFile.write(resourceFile.data(), resourceFile.size()) != resourceFile.size())
            {
            qWarning("Oups!");
            return;
            }
            localFile.close();

            QProcess::execute(localPath);@

            M Offline
            M Offline
            mkdh
            wrote on last edited by mkdh
            #5

            @MuldeR
            Not work!
            Error message: no match method.
            I find resourceFile.data() is const uchar *, but write must use const uchar *....

                    QFile file(myPath+"qqq.xxx");
                    file.open(QIODevice::WriteOnly);
                    //        QDataStream writer(file);
                    QResource resourceFile(":/xxx/Resources/xxx/qqq.xxx");
                    file.write(resourceFile.data(), resourceFile.size());
                    file.close();
            

            I am using Qt 5.4.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raf924
              wrote on last edited by raf924
              #6

              No nee to use the resource class, resource files can be accessed by QFile

              QFile resourceFile(":/path/to/resource");
              
              M 2 Replies Last reply
              0
              • R raf924

                No nee to use the resource class, resource files can be accessed by QFile

                QFile resourceFile(":/path/to/resource");
                
                M Offline
                M Offline
                mkdh
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • R raf924

                  No nee to use the resource class, resource files can be accessed by QFile

                  QFile resourceFile(":/path/to/resource");
                  
                  M Offline
                  M Offline
                  mkdh
                  wrote on last edited by mkdh
                  #8

                  @raf924
                  I got this file with 0 byte.

                  How to fixed it?

                         QFile file(myPath+"/qqq.xxx");
                          file.open(QIODevice::WriteOnly);
                          //QDataStream writer(file);
                          QFile resourceFile(":/xxx/Resources/xxx/qqq.xxx");
                          // QResource resourceFile(":/xxx/Resources/xxx/qqq.xxx");
                          file.write(resourceFile.readAll());
                          file.close();
                  

                  In fact, I just want to set the default file for the beinning user.
                  When user install this app, then he can get those free file.

                  But I don't know how to set those code and files....

                  R 1 Reply Last reply
                  0
                  • M mkdh

                    @raf924
                    I got this file with 0 byte.

                    How to fixed it?

                           QFile file(myPath+"/qqq.xxx");
                            file.open(QIODevice::WriteOnly);
                            //QDataStream writer(file);
                            QFile resourceFile(":/xxx/Resources/xxx/qqq.xxx");
                            // QResource resourceFile(":/xxx/Resources/xxx/qqq.xxx");
                            file.write(resourceFile.readAll());
                            file.close();
                    

                    In fact, I just want to set the default file for the beinning user.
                    When user install this app, then he can get those free file.

                    But I don't know how to set those code and files....

                    R Offline
                    R Offline
                    raf924
                    wrote on last edited by
                    #9

                    @mkdh You forgot to open the resource file.

                    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