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 764 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 richferrara

    I have a Qt Widgets application for Windows 11, and I would like to have a control on the front panel that launches a telnet window in a command prompt, which would run independently of the application until the user closes it. I am trying to find a way to do this with QProcess but nothing seems to work. The suggestions I've found online say to use QProcess to launch cmd.exe with the telnet command and parameters in the argument list, but it doesn't work. If I run my application from the Run menu in Qt Creator, I see some output in the Application Output tab, but it doesn't pop up a separate terminal. If I run it outside Qt Creator by double-clicking the executable, nothing happens. I tried using the C++ system command instead of QProcess -- this launches the telnet window but causes the GUI to be unresponsive until the window is closed. How can I make this work? It seems like there should be a way.

    JonBJ Online
    JonBJ Online
    JonB
    wrote last edited by JonB
    #2

    @richferrara said in Launch telnet from Qt GUI application:

    I am trying to find a way to do this with QProcess but nothing seems to work. The suggestions I've found online say to use QProcess to launch cmd.exe with the telnet command and parameters in the argument list, but it doesn't work.

    I tried using the C++ system command instead of QProcess -- this launches the telnet window

    Could you show precisely what you have tried (i.e. showing code and full command line) (a) with QProcess and (b) with system command. May be able to help --- this is my area but I only run Qt under Linux so it may be guesswork!

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

      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});

      Then I read online that I needed to run the command prompt instead and include telnet in the arguments list:
      QStringList args = {"/c", "telnet.exe", "172.99.99.99"}; // also tried "/k"; also tried no "/" argument
      QProcess::startDetached("cmd.exe", args);

      I also tried putting in the complete path to cmd.exe and telnet.exe, then I tried creating a QProcess object and using qProcess.start() instead of the static startDetached. Nothing worked.

      JonBJ 1 Reply Last reply
      0
      • richferraraR richferrara

        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});

        Then I read online that I needed to run the command prompt instead and include telnet in the arguments list:
        QStringList args = {"/c", "telnet.exe", "172.99.99.99"}; // also tried "/k"; also tried no "/" argument
        QProcess::startDetached("cmd.exe", args);

        I also tried putting in the complete path to cmd.exe and telnet.exe, then I tried creating a QProcess object and using qProcess.start() instead of the static startDetached. Nothing worked.

        JonBJ Online
        JonBJ Online
        JonB
        wrote last edited by JonB
        #4

        @richferrara
        Start with, say:

        QProcess p;
        QStringList args = {"/k", "telnet.exe"};
        p.start("cmd.exe", args);
        qDebug() << p.waitForStarted(3000);
        qDebug() << p.waitForFinished(3000);
        qDebug() << p.readAllStandardOutput() << p.readAllStandardError();
        

        Depending on what you get, try changing to:

        QStringList args = {"/c", "dir /s C:\\"};
        

        First thing is to figure out that you're getting the command right. Then deal with needing a console to run the telnet in.

        1 Reply Last reply
        0
        • 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 Online
            JonBJ Online
            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 Online
                JonBJ Online
                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 Online
                    JonBJ Online
                    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 Online
                        JonBJ Online
                        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 Online
                            JonBJ Online
                            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 Online
                                JonBJ Online
                                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