Results 1 to 8 of 8

Thread: How to communicate with external programs?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: customslots in qt4

    Quote Originally Posted by deekayt View Post
    Canyou suggest a better method to do this task.
    Use QProcess::startDetached(). This should work:
    Qt Code:
    1. QProcess::startDetached( "start", QStringList() << "something.jpg" );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by deekayt View Post
    Secondly I need to create , open , write , execute and close the file very often in my program on the click of buttons.
    Use QProcess.

    Please, don't ask unrelated questions in one thread --- open new thread for new issues. Also, please, use [ code ] tags for code snippets and [ quote ] tags only for quotes.

  2. #2
    Join Date
    May 2006
    Posts
    68
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10

    Default Re: How to communicate with external programs?

    Suppose I need to start any program which is there available in my computer by click of button from my designed form.
    I have created a QDialog and put a pushbutton. Then through a private slot I am trying to access the program ( or launch the program , say windows media player which is “wmplayer” ) which ideally should be detached from the parent program which I launch initially .
    I have tried QProcess with various combinations but it is not working.
    Where as if you type wmplayer on the command line run window the program runs.
    Interestingly when I type “cmd” that is the command line window it runs from myprogram and the command prompt for DOS opens up .But this is theonlyone which runs.

    The code is as
    Qt Code:
    1. steg::steg(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5. connect(ui.showdatafile, SIGNAL(clicked()), this, SLOT(showdatafile()));
    6.  
    7. }
    8.  
    9. void steg::showdatafile()
    10. {
    11. QProcess *myProcess ;
    12. QString program = "wmplayer";
    13. myProcess->startDetached(program);
    14. }
    To copy to clipboard, switch view to plain text mode 
    I have tried your suggestion also

    Qt Code:
    1. QProcess::startDetached( "start", QStringList() << "something.jpg" );
    To copy to clipboard, switch view to plain text mode 

    the code doesnot give any error.But when I click the button to launch it just doesnot run at all
    could you suggest some solution

  3. #3
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: How to communicate with external programs?

    Have a look on
    http://www.qtcentre.org/forum/f-qt-p...-doc-4178.html

    running only on mac & win .. linux dont have system urlhandler or file ecc...
    only webbsiteurl on the new QDesktopServices qt4.2

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: How to communicate with external programs?

    Quote Originally Posted by deekayt View Post
    myProcess->startDetached(program);
    QProcess::startDetached is a static method, you don't need any object to invoke it.

    How about this?
    Qt Code:
    1. QProcess::startDetached( "C:/full/path/to/wmplayer", QStringList() );
    To copy to clipboard, switch view to plain text mode 
    Also check the return value.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: How to communicate with external programs?

    Quote Originally Posted by deekayt View Post
    char encrypt_comand[]= " -e ";
    char key_comand[]= "-k=";
    char space[]= " ";

    QProcess p3;
    QStringList s3;
    s3 << space<< encrypt_comand<<ui.datalineEdit->text() <<space<< "coded.txt"<<space<<key_comand <<ui.passphraselineEdit->text();
    p3.startDetached(QString("burp.exe") , s3 );
    }
    Each entry in the string list "s3" should represent a single argument, so you shouldn't add any spaces, especially inside encrypt_command.

    It should be something like (note the + after key_command):
    Qt Code:
    1. char encrypt_comand[]= "-e";
    2. char key_comand[]= "-k=";
    3.  
    4. s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
    5. QProcess::startDetached( QString("/full/path/to/burp.exe"), s3 );
    To copy to clipboard, switch view to plain text mode 
    Make sure you specify full path to the executable, if it isn't in the current working directory (you might find QCoreApplication::applicationDirPath() useful).

    And, for the second time, QProcess::startDetached() is a static method, so you shouldn't create any QProcess instances to invoke it.

    Edit: Please, don't ask the same question in more than one thread. Threads merged.
    Last edited by jacek; 28th October 2006 at 00:58.

Similar Threads

  1. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 17:06
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 23:04
  3. Can't compile programs in Visual Studio.net 2005
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2006, 15:10

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
  •  
Qt is a trademark of The Qt Company.