Results 1 to 5 of 5

Thread: Running a bash script from resource (qrc) file

  1. #1
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Running a bash script from resource (qrc) file

    Linux / Qt4.6.3
    I want to run a shell script which I've placed in a .qrc resource.

    Qt Code:
    1. ...
    2. QString script(":/scripts/findttyusb.sh"); //<-- qp.waitForFinished() returns false (error)
    3. QString script("/root/Projects/UT804/UT804/scripts/findttyusb.sh"); //<--- works fine
    4. qp.start(script);
    5. if (qp.waitForFinished()){
    6. if (qp.exitCode() == 0){
    7. QByteArray result = qp.readAll();
    8. ...
    To copy to clipboard, switch view to plain text mode 

    Do I have to explicitly get the script out of the qrc, create a file and then execute it - or is there a really easy way to do this?
    Thanks for any thoughts.

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Running a bash script from resource (qrc) file

    I don't think, that this is possible, because resources are compilied into the binary.

  3. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Running a bash script from resource (qrc) file

    I suppose you could start bash in interactive mode and dump the script on its standard input, but this would be ugly, error-prone, and you would have to use the native API since QProcess only allows you to redirect the standard input to a file, not an arbitrary QIODevice.

  4. #4
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Running a bash script from resource (qrc) file

    Thanks for the thoughts people.

    I suspect I'm better off just running an external script as normal. In the back of my mind I seem to remember doing something similar with Qt a few years ago; but then, I'm getting old.

  5. #5
    Join Date
    Feb 2012
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Maemo/MeeGo

    Default Re: Running a bash script from resource (qrc) file

    Quote Originally Posted by yeye_olive View Post
    I suppose you could start bash in interactive mode and dump the script on its standard input, but this would be ugly, error-prone, and you would have to use the native API since QProcess only allows you to redirect the standard input to a file, not an arbitrary QIODevice.
    Perhaps ugly, but that seams to work:

    Qt Code:
    1. QProcess *proc = new QProcess;
    2. QString name = "/bin/bash";
    3. arg << "-c" ;
    4.  
    5. QFile file(":/test.sh");
    6. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    7. return 42;
    8.  
    9. arg << file.readAll();
    10. proc->start(name, arg);
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to spark82 for this useful post:

    TheIndependentAquarius (16th December 2015)

Similar Threads

  1. Running an script using QProcess
    By DiegoTc in forum Newbie
    Replies: 1
    Last Post: 31st December 2010, 18:02
  2. Running java script in QtWebKit makes GUI sluggish
    By calium in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2010, 09:35
  3. Running shell script with as super user in N900
    By spylvas in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 30th April 2010, 01:05
  4. Resource file in Qt4.4.0
    By jml in forum Qt Tools
    Replies: 0
    Last Post: 6th May 2008, 18:01
  5. Resource file in a lib
    By Rodrigo in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2007, 15:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.