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?

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.2k 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.
  • Y Offline
    Y Offline
    Yash001
    wrote on last edited by Yash001
    #1

    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?

    JonBJ mzimmersM 2 Replies Last reply
    0
    • Y Yash001

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Yash001
      Do you mean: you want your application to be passed a parameter on the command-line, and then you put that into a QLineEdit you show?

      1 Reply Last reply
      1
      • Y Offline
        Y Offline
        Yash001
        wrote on last edited by
        #3

        Yes exactly @JonB .

        if any change is detect in list qApp->arguments() then i would like to put string qApp->arguments().at(1) inside the QLineEdit.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          1
          • SGaistS SGaist

            Hi,

            QCommandLineParser ?

            Where is your QLineEdit located ?

            Y Offline
            Y Offline
            Yash001
            wrote on 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.

            aha_1980A 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              0
              • Y Yash001

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

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 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
                2
                • SGaistS SGaist

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

                  Y Offline
                  Y Offline
                  Yash001
                  wrote on 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
                  • aha_1980A aha_1980

                    @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 last edited by
                    #9

                    @aha_1980 Thank you for direction. let me try.

                    JonBJ 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 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
                      2
                      • Y Yash001

                        @aha_1980 Thank you for direction. let me try.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 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
                        2
                        • Y Yash001

                          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?

                          mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #12

                          @Yash001 have you considered using command line arguments?

                          Y 1 Reply Last reply
                          0
                          • mzimmersM mzimmers

                            @Yash001 have you considered using command line arguments?

                            Y Offline
                            Y Offline
                            Yash001
                            wrote on 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
                            • JonBJ JonB

                              @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 last edited by
                              #14

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

                              1 Reply Last reply
                              0
                              • SGaistS SGaist

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

                                Y Offline
                                Y Offline
                                Yash001
                                wrote on last edited by
                                #15

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

                                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