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. Launch telnet from Qt GUI application
Qt 6.11 is out! See what's new in the release blog

Launch telnet from Qt GUI application

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 522 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.
  • richferraraR Offline
    richferraraR Offline
    richferrara
    wrote last edited by
    #5

    Running the telnet command, I see this in the Application Output tab:

    true
    false
    "\r\nC:\[path to my executable]>" ""
    QProcess: Destroyed while process ("cmd.exe") is still running

    Running the dir command, I see the output of dir start displaying in the tab.

    I only see anything when I run my executable through Qt Creator's Run menu. If I run outside Qt Creator, I see no output.

    JonBJ 1 Reply Last reply
    0
    • richferraraR richferrara

      Running the telnet command, I see this in the Application Output tab:

      true
      false
      "\r\nC:\[path to my executable]>" ""
      QProcess: Destroyed while process ("cmd.exe") is still running

      Running the dir command, I see the output of dir start displaying in the tab.

      I only see anything when I run my executable through Qt Creator's Run menu. If I run outside Qt Creator, I see no output.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by JonB
      #6

      @richferrara
      I really would expect

      QStringList args = {"/c", "start telnet"};
      QProcess::startDetached("cmd", {args});
      

      to work, no? I am expecting this at least to open a terminal/console where you can interact with telnet. I do not expect it to get "destroyed". I expect it to work both inside and outside Creator. But I can't test anything.

      1 Reply Last reply
      0
      • richferraraR Offline
        richferraraR Offline
        richferrara
        wrote last edited by
        #7

        I figured it out.

        system("start telnet") works.

        JonBJ 1 Reply Last reply
        0
        • richferraraR richferrara

          I figured it out.

          system("start telnet") works.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by
          #8

          @richferrara said in Launch telnet from Qt GUI application:

          system("start telnet") works.

          As should the code I suggested sticking with QProcess.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote last edited by Christian Ehrlicher
            #9

            Why one needs to run a cmd.exe at all?

            Simply follow the docs

            QObject *parent = new QObject;
            ...
            QString program = "telnet";
            QStringList arguments;
            arguments << "172.99.99.99";
            
            QProcess *myProcess = new QProcess(parent);
            myProcess->start(program, arguments);
            

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Why one needs to run a cmd.exe at all?

              Simply follow the docs

              QObject *parent = new QObject;
              ...
              QString program = "telnet";
              QStringList arguments;
              arguments << "172.99.99.99";
              
              QProcess *myProcess = new QProcess(parent);
              myProcess->start(program, arguments);
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote last edited by JonB
              #10

              @Christian-Ehrlicher
              The OP essentially claimed to have tried this and claimed it did not work:

              The first thing I tried was just launching telnet directly:
              QStringList args = {"172.99.99.99"}; // using my target IP address
              QProcess::startDetached("telnet.exe", {args});
              

              That is why I tried "building up" step by step with them to see what was happening. Have you tried this under Windows (which I cannot do)? The question is whether the Windows' telnet opens any kind of "terminal/console/command" window for itself, the suggestion is it does not and hence is "invisible"?

              1 Reply Last reply
              0
              • richferraraR Offline
                richferraraR Offline
                richferrara
                wrote last edited by
                #11

                The windows telnet command normally runs in its own terminal window. For whatever reason, QProcess seems to only be capable of running applications in the background.

                JonBJ Christian EhrlicherC 2 Replies Last reply
                0
                • richferraraR richferrara

                  The windows telnet command normally runs in its own terminal window. For whatever reason, QProcess seems to only be capable of running applications in the background.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote last edited by JonB
                  #12

                  @richferrara
                  QProcess should be fine. You could also try having it run, say, notepad, if you don't think it can run e.g. a UI process. Did you actually try either my code or @Christian-Ehrlicher's ? If the Windows telnet opens its own window then you ought not need to run it via cmd/start? I guess I will be quiet now as I cannot test under Windows, maybe @Christian-Ehrlicher will.

                  1 Reply Last reply
                  0
                  • richferraraR richferrara

                    The windows telnet command normally runs in its own terminal window. For whatever reason, QProcess seems to only be capable of running applications in the background.

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote last edited by
                    #13

                    @richferrara said in Launch telnet from Qt GUI application:

                    For whatever reason, QProcess seems to only be capable of running applications in the background.

                    This is wrong. Please show your code and don't use QProcess::startDetached() if you want to interact with your application.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    JonBJ 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @richferrara said in Launch telnet from Qt GUI application:

                      For whatever reason, QProcess seems to only be capable of running applications in the background.

                      This is wrong. Please show your code and don't use QProcess::startDetached() if you want to interact with your application.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by
                      #14

                      @Christian-Ehrlicher said in Launch telnet from Qt GUI application:

                      and don't use QProcess::startDetached() if you want to interact with your application

                      Oh, really??

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @Christian-Ehrlicher said in Launch telnet from Qt GUI application:

                        and don't use QProcess::startDetached() if you want to interact with your application

                        Oh, really??

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote last edited by Christian Ehrlicher
                        #15

                        @JonB said in Launch telnet from Qt GUI application:

                        @Christian-Ehrlicher said in Launch telnet from Qt GUI application:

                        and don't use QProcess::startDetached() if you want to interact with your application

                        Oh, really??

                        That's the whole point of this function - fire and forget
                        https://doc.qt.io/qt-6/qprocess.html#startDetached

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        JonBJ 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @JonB said in Launch telnet from Qt GUI application:

                          @Christian-Ehrlicher said in Launch telnet from Qt GUI application:

                          and don't use QProcess::startDetached() if you want to interact with your application

                          Oh, really??

                          That's the whole point of this function - fire and forget
                          https://doc.qt.io/qt-6/qprocess.html#startDetached

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote last edited by JonB
                          #16

                          @Christian-Ehrlicher said in Launch telnet from Qt GUI application:

                          and don't use QProcess::startDetached() if you want to interact with your application

                          and

                          That's the whole point of this function - fire and forget
                          https://doc.qt.io/qt-6/qprocess.html#startDetached

                          Hi Christian. I am sorry but I do not agree with your statements. Under Linux at least startDetached() causes the child process not to get killed when the parent process exits, but it is not true to say that means you do not use if you need interaction.

                          Testing under Linux at least, where telnet does not open its own window (maybe it does under Windows, I don't know) while, say, gedit does, I see the following behaviour:

                          • start("telnet"): runs telnet (in the background), no window, exiting Qt app kills the telnet.
                          • startDetached("telnet"): same as start(), but exiting Qt app does not kill the telnet.
                          • start("gedit"): runs gedit, that creates its own window and interacts fine, exiting Qt app kills the gedit.
                          • startDetached("gedit"): same as start(), but exiting Qt app does not kill the gedit.

                          If I want a Linux spawned telnet to be visible and have a window I have to use something like e.g. xterm -e telnet as the command. And again that behaves as above: dies on parent exit with start(), continues to run afterwards with startDetached(), but same interaction in both cases.

                          Maybe it's different under Windows and/or with telnet there, but saying that "and don't use QProcess::startDetached() if you want to interact with your application" is not the story under Linux at least. Which is why I expressed my surprise when you wrote that, as not my experience in Linux.

                          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