PDA

View Full Version : QProcess in main() opens multiple instances



gojkovicde
9th December 2012, 16:53
Hi,
I want to create an application that will open a terminal. The terminal should be the main window of the application.
I'd use custom classes, and show member values, and function results in the terminal.

The problem is that when I run the application (code below), it keeps opening terminals (one each second) until I close it.
It wouldn't open just one instance of a terminal. I know that app.exec() creates a loop, but I've seen posts all over the Internet
where people do open external programs using QProcess in the same manner.

textdrive.pro


TARGET = textDrive
TEMPLATE = app
SOURCES = main.cpp
QT -= gui


main.cpp


#include <QCoreApplication>
#include <QProcess>
#include <QStringList>
#include <QDebug>

int main (int argc, char *argv[])
{

QCoreApplication app(argc, argv);

QProcess *proc = new QProcess(&app);
proc->start("konsole", QStringList() << "--hide-menubar" << "-e" << "/home/dejan/projects/linux/txtdrive/textDrive");
qDebug() << "Console application running!";

return app.exec();

}


I'm running it on Arch Linux.

Thank you for your help,
Dejan

ChrisW67
10th December 2012, 00:27
QProcess starts the process once only.

Konsole does not have command line option "--hide-menubar" in my installation so QProcess fails to launch the konsole instance. Assuming that you have a different konsole... you are asking konsole to execute a script when it starts. What is that script doing?

gojkovicde
10th December 2012, 07:43
I was looking at it for so long, that I couldn't see that the script is running the program AGAIN! I assumed that I needed that in order to QDebug part to be printed, and I was right about that, but forgot the side effects...

Thank you for your help...