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. How can I set the string QLineEdit in application with help of other application or shell script?
Forum Updated to NodeBB v4.3 + New Features

How can I set the string QLineEdit in application with help of other application or shell script?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.11.1win32windowsshell
15 Posts 5 Posters 2.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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 16 Nov 2018, 20:54 last edited by
    #4

    Hi,

    QCommandLineParser ?

    Where is your QLineEdit located ?

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

    Y 1 Reply Last reply 16 Nov 2018, 22:11
    1
    • S SGaist
      16 Nov 2018, 20:54

      Hi,

      QCommandLineParser ?

      Where is your QLineEdit located ?

      Y Offline
      Y Offline
      Yash001
      wrote on 16 Nov 2018, 22:11 last edited by
      #5

      @SGaist Thank you for direction.

      QLineEdit is located inside MainWindow.cpp file. I am trying to change path from main.cpp file. I create the instance of MainWindow inside the main.cpp, and calling member function of MainWindow for changing string in QLineEdit.

      In addition, Users are not able open multiple instance of application.

      Now, I am able to set the argument inside the QLineEdit. whenever I open first time my application.

      But if second time user will call application with command line arguments, at that time it is open old instance of application, and it is correct but it won't change the string in QLineEdit.

      I need some kind of functionality which is detect the change in qApp->arguments() list and notify to QLineEdit for changing string.

      A 1 Reply Last reply 17 Nov 2018, 07:07
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 16 Nov 2018, 22:17 last edited by
        #6

        What are you using to have a single instance of your application ?

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

        Y 1 Reply Last reply 21 Nov 2018, 17:02
        0
        • Y Yash001
          16 Nov 2018, 22:11

          @SGaist Thank you for direction.

          QLineEdit is located inside MainWindow.cpp file. I am trying to change path from main.cpp file. I create the instance of MainWindow inside the main.cpp, and calling member function of MainWindow for changing string in QLineEdit.

          In addition, Users are not able open multiple instance of application.

          Now, I am able to set the argument inside the QLineEdit. whenever I open first time my application.

          But if second time user will call application with command line arguments, at that time it is open old instance of application, and it is correct but it won't change the string in QLineEdit.

          I need some kind of functionality which is detect the change in qApp->arguments() list and notify to QLineEdit for changing string.

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 17 Nov 2018, 07:07 last edited by
          #7

          @Yash001

          I need some kind of functionality which is detect the change in qApp->arguments() list and notify to QLineEdit for changing string.

          There is no «change of arguments». every program has its own set of arguments, and they are fully separated.

          the only thin you can do is, from the second prog instance detect that there is already an instance running and send the new strings by inter-process communication.

          Qt has to stay free or it will die.

          Y 1 Reply Last reply 21 Nov 2018, 17:19
          2
          • S SGaist
            16 Nov 2018, 22:17

            What are you using to have a single instance of your application ?

            Y Offline
            Y Offline
            Yash001
            wrote on 21 Nov 2018, 17:02 last edited by
            #8

            @SGaist I am using windows API and Last save name of application to identify the running instance.

            QStringList GetProcessList() {
            	QStringList ret;
            
            	QProcess process;
            	process.setReadChannel(QProcess::StandardOutput);
            	process.setReadChannelMode(QProcess::MergedChannels);
            	process.start("wmic.exe /OUTPUT:STDOUT PROCESS get Caption");
            	process.waitForStarted(1000);
            	process.waitForFinished(-1);
            
            
            	QTextStream txtStr(&process);
            
            	while (!txtStr.atEnd()) {
            		auto line = txtStr.readLine().trimmed();
            		ret << line;
            	}
            	
            	return ret;
            }
            

            this code will return the QstringList, which is contain QFileInfo(qApp->applicationFilePath()).fileName(); if application is running.

            1 Reply Last reply
            0
            • A aha_1980
              17 Nov 2018, 07:07

              @Yash001

              I need some kind of functionality which is detect the change in qApp->arguments() list and notify to QLineEdit for changing string.

              There is no «change of arguments». every program has its own set of arguments, and they are fully separated.

              the only thin you can do is, from the second prog instance detect that there is already an instance running and send the new strings by inter-process communication.

              Y Offline
              Y Offline
              Yash001
              wrote on 21 Nov 2018, 17:19 last edited by
              #9

              @aha_1980 Thank you for direction. let me try.

              J 1 Reply Last reply 21 Nov 2018, 17:49
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 21 Nov 2018, 17:36 last edited by
                #10

                You should consider using QtSingleApplication. It's meant for that kind of cases.

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

                Y 1 Reply Last reply 26 Nov 2018, 18:38
                2
                • Y Yash001
                  21 Nov 2018, 17:19

                  @aha_1980 Thank you for direction. let me try.

                  J Offline
                  J Offline
                  JonB
                  wrote on 21 Nov 2018, 17:49 last edited by JonB
                  #11

                  @Yash001
                  The fact remains that regardless of the whole single instance issue, as @aha_1980 has said there is no capability to "change command line of a running application". qApp->arguments() will never return a different result no matter what you try to do. Unless you restart your application for a new string, the only way to approach this will be some kind of IPC connecting to the running program to alter anything in it.

                  Y 1 Reply Last reply 26 Nov 2018, 18:36
                  2
                  • Y Yash001
                    16 Nov 2018, 19:25

                    I would like to set the string in QLineedit from shell script whenever my application is run. How can i call the QlineEdit of the application from external application or shell script?

                    Is it any way to do it in Qt?

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 21 Nov 2018, 19:10 last edited by
                    #12

                    @Yash001 have you considered using command line arguments?

                    Y 1 Reply Last reply 26 Nov 2018, 18:34
                    0
                    • M mzimmers
                      21 Nov 2018, 19:10

                      @Yash001 have you considered using command line arguments?

                      Y Offline
                      Y Offline
                      Yash001
                      wrote on 26 Nov 2018, 18:34 last edited by
                      #13

                      @mzimmers Yes, With help of Shell script I am sending string to my application. It will updated int argc, char *argv[] on another instance.

                      1 Reply Last reply
                      0
                      • J JonB
                        21 Nov 2018, 17:49

                        @Yash001
                        The fact remains that regardless of the whole single instance issue, as @aha_1980 has said there is no capability to "change command line of a running application". qApp->arguments() will never return a different result no matter what you try to do. Unless you restart your application for a new string, the only way to approach this will be some kind of IPC connecting to the running program to alter anything in it.

                        Y Offline
                        Y Offline
                        Yash001
                        wrote on 26 Nov 2018, 18:36 last edited by
                        #14

                        @JonB Yup. I am working on that approach. Thank you.

                        1 Reply Last reply
                        0
                        • S SGaist
                          21 Nov 2018, 17:36

                          You should consider using QtSingleApplication. It's meant for that kind of cases.

                          Y Offline
                          Y Offline
                          Yash001
                          wrote on 26 Nov 2018, 18:38 last edited by
                          #15

                          @SGaist Thank you inform about me QtSingleApplication class. I will modify code and use QtSingleApplication.

                          1 Reply Last reply
                          0

                          13/15

                          26 Nov 2018, 18:34

                          • Login

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