How can I set the string QLineEdit in application with help of other application or shell script?
-
@SGaist Thank you for direction.
QLineEdit
is located insideMainWindow.cpp
file. I am trying to change path frommain.cpp
file. I create the instance ofMainWindow
inside themain.cpp
, and calling member function ofMainWindow
for changing string inQLineEdit
.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 toQLineEdit
for changing string. -
What are you using to have a single instance of your application ?
-
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.
-
@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. -
You should consider using QtSingleApplication. It's meant for that kind of cases.
-
@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.