Results 1 to 9 of 9

Thread: How execute a script in a Qt aplication?

  1. #1
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How execute a script in a Qt aplication?

    Hello!

    I'm trying to execute a script in a QT aplication.

    The shell is "sh" and the script is "calibrate.sh". (this script calibrates the touchscreen of embeeded linux device).

    In the terminal the script works using the next command:

    ----> root@device /opt$ sh calibrate.sh

    The code used is this, the function is a public slot (this slot is called when you push a QPushButton):

    Qt Code:
    1. void proves::execapp(){
    2.  
    3. QStringList argo,list;
    4. QProcess * exec;
    5. exec =new QProcess(this);
    6.  
    7. argo <<"/opt/calibrate.sh";
    8. list <<"PATH=/opt:/opt/p:/bin:";
    9.  
    10. exec->setEnvironment(list);
    11. exec->start("/bin/sh", argo);
    12. }
    To copy to clipboard, switch view to plain text mode 

    but it don't works...

    What's wrong??


    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How execute a script in a Qt aplication?

    Does your script contain a shebang? By the way, how do you know it doesn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How execute a script in a Qt aplication?

    hello Wysota!

    The shebang was incorrect --->#!/bin/bash, now is correct--->#!/bin/sh

    i've modified the code:

    Qt Code:
    1. void proves::execapp(){
    2.  
    3. QStringList argo,list;
    4. argo.clear();
    5. list.clear();
    6.  
    7. QProcess * exec;
    8.  
    9. exec =new QProcess(this);
    10. list <<"PATH=/opt:/opt/p:/bin:";
    11. exec->setEnvironment(list);
    12. exec->start("./calibrate.sh");
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    To know if it works or no:

    1. I don't see the calibrate application in the touchscreen.
    2. I use the command "top" to see the PID of the executing process. The last tests using the new code, I can see executing new zombie process every time i pressed the button to calibrate touchscreen... but in screen only appears the qt application

    Note: To make the tests, in putty terminal i write next commands:

    1) ./projecte -qws & (to execute the qt application)
    2) top ( to see PIDS)
    3) I press the buton to execute calibrate application ( it is a graphic application)

    In touchscreen only appears the qt application but no calibrate application...
    Last edited by wysota; 6th September 2011 at 11:57.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How execute a script in a Qt aplication?

    The fact that the screen doesn't pop up doesn't mean the script is not executed. It might just work incorrectly. Furthermore where is your script located? Since you are running the script from current working directory, did you make sure the working directory is set correctly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How execute a script in a Qt aplication?

    yes yes, the script is in /opt/

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How execute a script in a Qt aplication?

    But what the current working directory is? Did you explicitly set it to /opt? What happens if you call the script as /opt/script.sh instead of ./script.sh?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How execute a script in a Qt aplication?

    If i put next code:

    void proves::execapp(){

    QStringList argo,list;
    argo.clear();
    list.clear();

    QProcess * exec;
    exec =new QProcess(this);
    list <<"PATH=/usr/bin/:/bin/:/opt/:/opt/p/:";
    exec->setEnvironment(list);
    exec->start("/opt/calibrate.sh");

    }

    the results are worse, don't appear new PIDs

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How execute a script in a Qt aplication?

    You forgot to start sh.

    Qt Code:
    1. exec->start("/bin/sh", QStringList() << "/opt/calibrate.sh");
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How execute a script in a Qt aplication?

    I found the solution....

    the code was correct in all cases.

    in the code i added this line:

    exec->setProcessChannelMode(QProcess::ForwardedChannels );

    Then, when i press the button, in the terminal out the next line:

    TS_OPEN: not such file name.

    TS_OPEN is internal function of TS_LIB, libray of touchScreen control. This function need the specific device of touchScreen.

    To solve this, i added the variable TSLIB_TSDEVICE in environment ---> QStringList list <<"PATH=/opt:/opt/p:/usr/bin:/bin:/sbin:/usr/local/bin:/usr/etc:"<<"TSLIB_TSDEVICE=/dev/input/event1";

    that's all

    thanks for your time

Similar Threads

  1. Simple CAD aplication - how to
    By tommnaj in forum Newbie
    Replies: 3
    Last Post: 5th April 2011, 23:47
  2. Aplication just works where it was compile
    By metRo_ in forum Qt Programming
    Replies: 7
    Last Post: 13th April 2010, 00:02
  3. How can i execute a database script within Qt?
    By NoRulez in forum Qt Programming
    Replies: 3
    Last Post: 14th January 2010, 09:37
  4. How to Execute Qt script from Qt
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2007, 10:12
  5. Creating a STANDALONE aplication
    By Alienxs in forum KDE Forum
    Replies: 4
    Last Post: 17th August 2006, 17:02

Tags for this Thread

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.