Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt to linux terminal
Forum Updated to NodeBB v4.3 + New Features

Qt to linux terminal

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thehilmisu
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TheDestroyer
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thehilmisu
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Scylla
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thehilmisu
            wrote on last edited by
            #5

            [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;@
            
            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on last edited by
              #6

              @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 )@

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Scylla
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thehilmisu
                  wrote on last edited by
                  #8

                  [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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved