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. Include program in resources
Forum Updated to NodeBB v4.3 + New Features

Include program in resources

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.0k 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.
  • J Offline
    J Offline
    jocala
    wrote on last edited by
    #1

    I'm using Qt 5.3 on OS X. I have a program that depends on the android tool adb, so I'm trying to include it as a resource.

    In my .pro file I have

    @RESOURCES = app.qrc@

    In app.qrc I have:
    @
    <!DOCTYPE RCC><RCC version="1.0">
    <qresource>
    <file>assets/adb</file>
    </qresource>
    @

    In my app:

    @

    QResource::registerResource("app.rcc");

    QProcess *kill_adb=new QProcess;
    kill_adb->start("/assets/adb kill-server");
    kill_adb->waitForFinished(-1);
    int exitcode = kill_adb->exitCode();

    QString s = QString::number(exitcode);
    QMessageBox::critical(
    this,
    tr("exit code:"),
    s);
    delete kill_adb;
    @

    Calls to /assets/adb fail. If I use a path to a local adb the code works. How can I include adb with my program?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You don't need to register resources that are defined in qmake's RESOURCES variable: it is done automatically for you.

      The path to ADB is wrong; it should be:
      @
      ":/assets/adb"
      // or
      "qrc:///assets/adb"
      @

      (Z(:^

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

        I'm not an expert on OS X, but normally you cannot run programs directly from the resources. For the operating system, the file does not exist, after all. Instead, you'll need to "extract" the resource to a temporary file, at runtime, before you can launch it as a program. At least that's what I currently do. I don't think QProcess handles this transparently. Does it?

        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
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          [quote author="MuldeR" date="1401023977"]I'm not an expert on OS X, but normally you cannot run programs directly from the resources. For the operating system, the file does not exist, after all. Instead, you'll need to "extract" the resource to a temporary file, at runtime, before you can launch it as a program. At least that's what I currently do. I don't think QProcess handles this transparently. Does it?[/quote]

          You are most probably right. I forgot to mention that in my previous post. Let's see what the OP finds out.

          (Z(:^

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jocala
            wrote on last edited by
            #5

            Thanks for the feedback. How do you extract a resource?

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

              You can do something like:
              @bool bSuccess = false;
              const QString binPath = QString("%1/adb_%2").arg(
              QDir::tempPath(),
              QString::number(qrand())
              );

              QResource myRes(":/assets/adb");
              if(myRes.isValid())
              {
              QFile outFile(binPath);
              if(outFile.open(QIODevice::WriteOnly)
              {
              if(outFile.write(myRes.data(), myRes.size()) == myRes.size())
              {
              bSuccess = true;
              qDebug("Success! :-)";
              }
              outFile.close();
              }
              }

              if(bSuccess)
              {
              QProcess *kill_adb=new QProcess;
              kill_adb->start(binPath);
              kill_adb->waitForFinished(-1);
              }@

              (Note: On Unix-like OS you might also need to setup the permissions)

              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
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                And also check if adb as any non-system dependencies. At least on OS X it doesn't seem so.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jocala
                  wrote on last edited by
                  #8

                  Thanks for the replies! Things are a little clearer now :)

                  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