Qt to linux terminal



  • Hi everyone,

    I wanted to write code and control the linux terminal from it's gui. Is there any chance to write command to terminal from
    my project ?

    Thanks in advance.



  • yes you can, but you can't see the result. This thing is independent from Qt. It's a function:

    int system(const char*)

    so for example, just type in the main() function (without Qt stuff)

    @
    int main()
    {
    system("mkdir ~/testDir");
    }
    @

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • [quote author="TheDestroyer" date="1329157511"]yes you can, but you can't see the result. This thing is independent from Qt. It's a function:

    int system(const char*)

    so for example, just type int he main() function (without Qt stuff)

    int main()
    {
    system("mkdir ~/testDir")
    }[/quote]

    Thanks.



  • But you I think you should use "QProcess":http://doc.trolltech.com/4.8-snapshot/qprocess.html . So you can read and write the console output.



  • [quote author="Scylla" date="1329202322"]But you I think you should use "QProcess":http://doc.trolltech.com/4.8-snapshot/qprocess.html . So you can read and write the console output.[/quote]

    Thank you for your answer. But i have a question again, how can i read the console output? I tried this but i could not see the output. I think i get this wrong =)

    Thanks

    @QProcess test;
    test.start("ls", QStringList() << "-a");

    test.write("ls");
    test.closeWriteChannel();
    
    QByteArray result = test.readAll();
    
    qDebug()<<"gelen :"<<result;@


  • @test.waitForFinished();
    qDebug() << "gelen :"<<test.readAllStandardOutput ();@

    or use singal/slots:
    @void error ( QProcess::ProcessError error )
    void finished ( int exitCode, QProcess::ExitStatus exitStatus )
    void readyReadStandardError ()
    void readyReadStandardOutput ()
    void started ()
    void stateChanged ( QProcess::ProcessState newState )@



  • Take looke at the small "example":http://pastebin.com/xX0DLc5q here. I hope this helps you to understan how it works.



  • [quote author="AcerExtensa" date="1329207608"]@test.waitForFinished();
    qDebug() << "gelen :"<<test.readAllStandardOutput ();@

    or use singal/slots:
    @void error ( QProcess::ProcessError error )
    void finished ( int exitCode, QProcess::ExitStatus exitStatus )
    void readyReadStandardError ()
    void readyReadStandardOutput ()
    void started ()
    void stateChanged ( QProcess::ProcessState newState )@[/quote]

    i've solved it thanks =) appearantly i have to put the "waitForFinished()" method.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.