Results 1 to 3 of 3

Thread: executing script from c++ code

  1. #1

    Default executing script from c++ code

    I develop an application using Qt/c++/ubuntu (further parent app).
    I need to execute another open source application from my c++ code (further child app).
    To run child application is to execute a bash script. The script sets several global variables and then calls python application.
    The script works well from command line.

    I tried to use Qt QProcess class but I have got only cascade of error messages from child python application.
    Can I use embedding python into my c++ code by means of functions from Python.h?
    What need I to do with global variables in the case?

    Please give me an advice to call the script from c++ code. What is my alternatives? What is the best of them?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: executing script from c++ code

    What did you run as QProcess?
    You may want to run bash shell as QProcess and script as an argurmant.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3

    Default Re: executing script from c++ code

    Dear Santosh, thank you.

    Here is fragment of my code:

    Qt Code:
    1. //-------------------
    2. void MainWindow::CodeAsterError()
    3. {
    4. ui->textBrowserError->append(caProcess->readAllStandardError());
    5. }
    6.  
    7. void MainWindow::CodeAsterOut()
    8. {
    9. QByteArray byteArray = caProcess->readAllStandardOutput();
    10. QStringList strLines = QString(byteArray).split("\n");
    11.  
    12. foreach (QString line, strLines)
    13. {
    14. ui->textBrowserOut->append(line);
    15. }
    16. }
    17.  
    18. void MainWindow::on_pushButton_clicked()
    19. {
    20. QString program = "/home/oogolov/aster/bin/as_run";
    21. QStringList arguments;
    22. arguments << "/home/oogolov/GeoFEA/GeoFEA2D/WorkDir/Calc.export";
    23.  
    24. connect (caProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(CodeAsterOut()));
    25. connect (caProcess, SIGNAL(readyReadStandardError()), this, SLOT(CodeAsterError()));
    26.  
    27. caProcess->start(program,arguments);
    28. //caProcess->start("/bin/bash", QStringList() << "/home/oogolov/aster/bin/as_run" << "/home/oogolov/GeoFEA/GeoFEA2D/WorkDir/Calc.export");
    29. // commented operator works too
    30. caProcess->waitForReadyRead(100);
    31. }
    32. //----------------------
    To copy to clipboard, switch view to plain text mode 

    When I run (Build/Run) my application it works. But when I debug (Debug/Start Debugging) I get following error:

    *************************
    Traceback (most recent call last):
    File "<string>", line 1, in <module>

    File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/main.py", line 109, in main
    start()
    File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/main.py", line 51, in start
    run = AsterRun()
    File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/run.py", line 186, in __init__
    self.LoadExtensions()
    File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/run.py", line 297, in LoadExtensions
    import asrun.maintenance
    File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/maintenance.py", line 42, in <module>

    from asrun.build import AsterBuild
    File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/build.py", line 31, in <module>
    from zipfile import ZipFile
    File "/opt/QtSDK/debugger/Desktop/lib/python2.7/zipfile.py", line 6, in <module>
    import io
    File "/opt/QtSDK/debugger/Desktop/lib/python2.7/io.py", line 60, in <module>
    import _io
    ImportError: /opt/QtSDK/debugger/Desktop/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_FromObject
    ****************************

    Could you help me to repair this "Import, PyUnicode" state?
    Last edited by wysota; 14th January 2013 at 12:26. Reason: missing [code] tags

Similar Threads

  1. executing a audio player code on Embedded linux
    By sureshlohith in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 21st April 2010, 06:17
  2. Replies: 1
    Last Post: 27th February 2010, 11:33
  3. [Advanced] Qt Script access QObject from C++ code
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 21st May 2009, 23:10
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 04:01
  5. Executing C++ before and after main()
    By fullmetalcoder in forum General Programming
    Replies: 18
    Last Post: 13th May 2007, 09:28

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.