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. Interaction between a terminal and a window

Interaction between a terminal and a window

Scheduled Pinned Locked Moved General and Desktop
16 Posts 6 Posters 5.6k Views
  • 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.
  • Z Offline
    Z Offline
    Zikkee13
    wrote on last edited by
    #3

    I can't use a graphical interface for this part. It's mentionned in the specifications of my project. :/

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      Then make two applications (one CLI, one GUI) and use IPC to make one interact with the other.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zikkee13
        wrote on last edited by
        #5

        I can't do this in an other way?
        I saw we can specify a terminal for in/out in Environment->Terminal. If I specify one terminal in this field can I do what I want?
        I tried to specify a terminal but when I launch my app no terminal is launched...

        Thanks

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #6

          You can tick the "run in terminal" checkbox in Projects->Run Settings. Is that what you want?

          Note that your code will not work as you expect (I guess): It will wait for a number before it even draws your window.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zikkee13
            wrote on last edited by
            #7

            Yes, thanks Toblas. ;)

            You are right, because of the QApplication::exec() my app doesn't work.
            My terminal waits for my window is closed or my loop blocks the exec() of my window. But I want the two windows (terminal and displaying zone of my shape) in parallel.

            I think I have to use QThread to do what I want. I guess someting like that :

            • I have a general class which contains an instance of my terminal and an instance of my window which displays shapes
            • the loop of my terminal is performed by a QThread to allow my window displays shapes during the loop

            Am I right?

            I have an other question about the terminal. How can I display a terminal in a new Window with its content produced by a QThread (I/O) ?

            Thanks for your help!

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

              maybe create two different applications (one with gui the other as terminal) then use QProcess in gui to call terminal and the read/write terminal ? QProcess acts as standard QIODevice.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MuldeR
                wrote on last edited by
                #9

                Yup, if you create your console process via QProcess, you can write to its STDIN via the QProcess object and also read its STDOUT and STDERR that way. That should allow for basic interaction.

                A more sophisticated method, which also works if the console application is not created via QProcess (it may already be running), would be something based on QSharedMemory and QSystemSemaphore. That's what I usually do to implement communication between several instances of my application. Works fine for me.

                My OpenSource software at: http://muldersoft.com/

                Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                Go visit the coop: http://youtu.be/Jay...

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  Zikkee13
                  wrote on last edited by
                  #10

                  OK. So if I create a QProcess that launches a new terminal and executes a program (my loop which asks the number to the user), can my executed program in the QProcess can interact with the QProcess and the QProcess interact with my "general app"? For instance if I want my executed program in the QProcess returns a list of numbers to my general app. Can I use signals/slots or something else to do the connection between the different components?

                  Thanks

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MuldeR
                    wrote on last edited by
                    #11

                    Your GUI application ("general app") would launch the Console application as a new process via QProcess. Then the GUI app controls the Console application/process via the QProcess object. More specifically, everything the Console app writes to its STDOUT or STDERR, i.e. the output that normally would appear as Text on the Console window, will go straight to the QProcess object and can be read and processed from there, by the GUI application. It's also possible to write to the Console process' STDIN via the QProcess object, to send some data "back", which is like a user would type into the Console window...

                    QProcess has useful readyReadStandardOutput() and readyReadStandardError() signals, which will tell you when new output from the Console app has become available...

                    My OpenSource software at: http://muldersoft.com/

                    Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                    Go visit the coop: http://youtu.be/Jay...

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      If you want to use QProcess to pilot your second program, the only option is to parse the output from QProcess (using readyRead for example to know when new data has come out of your CLI) and act accordingly.

                      If you wan't something more sophisticated, you'll need some form of IPC.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        Zikkee13
                        wrote on last edited by
                        #13

                        I think I'm going to use IPC system.
                        So I can create shared memory with QSharedMemory class.
                        But can I share a memory segment created with QSharedMemory object with a process that doesn't use Qt classes? (so it uses shm* functions). Because when I set a key to my QSharedMemory, the type of the key is QString.
                        Thanks!

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MuldeR
                          wrote on last edited by
                          #14

                          See here:
                          http://qt-project.org/forums/viewthread/21411

                          (It's about a QSystemSemaphore, but the point is exactly the same)

                          EDIT: Link fixed.

                          My OpenSource software at: http://muldersoft.com/

                          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                          Go visit the coop: http://youtu.be/Jay...

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            tobias.hunger
                            wrote on last edited by
                            #15

                            Do you want a terminal or just an area where the user can enter text?

                            1 Reply Last reply
                            0
                            • Z Offline
                              Z Offline
                              Zikkee13
                              wrote on last edited by
                              #16

                              Thanks, MuldeR.
                              Tobias Hunger, I need a terminal. ;)

                              I have another question : if I share memory between the two components, how can the GUI be notified that the value of the shared memory has changed? For exemple the terminal writes a list of numbers in this shared memory and changes it : my GUI needs to load the new list of numbers.

                              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