Results 1 to 3 of 3

Thread: QProcess in main() opens multiple instances

  1. #1
    Join Date
    May 2012
    Location
    Serbia, Sabac
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post QProcess in main() opens multiple instances

    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
    Qt Code:
    1. TARGET = textDrive
    2. TEMPLATE = app
    3. SOURCES = main.cpp
    4. QT -= gui
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QProcess>
    3. #include <QStringList>
    4. #include <QDebug>
    5.  
    6. int main (int argc, char *argv[])
    7. {
    8.  
    9. QCoreApplication app(argc, argv);
    10.  
    11. QProcess *proc = new QProcess(&app);
    12. proc->start("konsole", QStringList() << "--hide-menubar" << "-e" << "/home/dejan/projects/linux/txtdrive/textDrive");
    13. qDebug() << "Console application running!";
    14.  
    15. return app.exec();
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    I'm running it on Arch Linux.

    Thank you for your help,
    Dejan

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess in main() opens multiple instances

    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?

  3. The following user says thank you to ChrisW67 for this useful post:

    gojkovicde (10th December 2012)

  4. #3
    Join Date
    May 2012
    Location
    Serbia, Sabac
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess in main() opens multiple instances

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

Similar Threads

  1. Replies: 11
    Last Post: 24th July 2012, 12:39
  2. Replies: 2
    Last Post: 19th October 2011, 09:30
  3. Multiple instances of QWebView
    By darious in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2011, 07:55
  4. Replies: 6
    Last Post: 1st July 2010, 12:02
  5. Multiple program instances
    By scwizard in forum Qt Programming
    Replies: 13
    Last Post: 1st April 2007, 17:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.