Results 1 to 3 of 3

Thread: how to start a program in the background

  1. #1
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default how to start a program in the background

    I have two Windows programs; A and B. Program A is a QApplication with a GUI. Program B is a QCoreApplication without a GUI. I need A to kick off B and keep focus on A. When I use QProcess it starts B in a console window, but leaves that as the active window on the system. I am looking for ideas on this....

  2. #2
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to start a program in the background

    setFocus() on the QMainWindow of A?

  3. #3
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to start a program in the background (solved)

    I finally have a solution to this issue.

    Part of the problem was QProcess appears to return too fast. It needs a second for the new process to get going before I try to put my main application back into focus.

    Here is the nature of what I did.

    bool status = newProcess->startDetached( command, QStringList(), path );

    // qprocess appears to operate on events internally, be sure it happens
    QTime startTime = QTime::currentTime();
    while( startTime.msecsTo( QTime::currentTime() ) < 100 )
    {
    QCoreApplication:rocessEvents();
    }

    // ensure focus is returned to the main window
    if( returnFocus )
    {
    while( !mainWindow->isActiveWindow() )
    {
    mainWindow->show();
    mainWindow->activateWindow();
    mainWindow->raise();
    }
    }

Similar Threads

  1. Start program with right button
    By Pablo128 in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2010, 14:03
  2. Can't start a qt-program on embedded linux
    By Tschounes in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 6th June 2010, 00:39
  3. add a program to start menu
    By kpmsivachand in forum KDE Forum
    Replies: 1
    Last Post: 26th January 2009, 21:19
  4. How to hide mainwindow at program start up
    By palmer in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2008, 15:35
  5. QProcess start a console program
    By Shawn in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2007, 13:38

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.