Results 1 to 2 of 2

Thread: How to set window to active window based on QProcess?

  1. #1
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    1
    Thanked 4 Times in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default How to set window to active window based on QProcess?

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QMessageBox>
    4. #include <QTextStream>
    5. #include <QTime>
    6. #include <QProcess>
    7. #include <QFile>
    8.  
    9. QString path;
    10.  
    11. MainWindow::MainWindow(QWidget *parent) :
    12. QMainWindow(parent),
    13. ui(new Ui::MainWindow)
    14. {
    15. ui->setupUi(this);
    16. ui->lineEdit->setValidator(new QIntValidator(this));
    17. ui->statusBar->showMessage("Waiting for input...");
    18. QFile file("path.txt");
    19. if(!file.open(QIODevice::ReadOnly)) {
    20. QMessageBox::information(0, "Error", file.errorString());
    21. }
    22. QTextStream in(&file);
    23. path = in.readLine();
    24. file.close();
    25. }
    26.  
    27. MainWindow::~MainWindow()
    28. {
    29. delete ui;
    30. }
    31.  
    32. void MainWindow::on_pushButton_2_clicked()
    33. {
    34. qApp->exit();
    35. }
    36.  
    37. void delay(int n)
    38. {
    39. QTime dieTime = QTime::currentTime().addSecs(n);
    40. while(QTime::currentTime() < dieTime)
    41. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    42. }
    43.  
    44. void MainWindow::on_pushButton_clicked()
    45. {
    46. ui->pushButton->setEnabled(false);
    47. qint32 waitSecs = ui->lineEdit->text().toInt();
    48. QTime launchTime = QTime::currentTime().addSecs(waitSecs);
    49.  
    50. while(waitSecs > 0) {
    51. waitSecs = QTime::currentTime().secsTo(launchTime);
    52. ui->statusBar->showMessage(QString("Waiting %1 seconds to launch BLR launcher.").arg(waitSecs));
    53. delay(1);
    54. }
    55.  
    56. ui->statusBar->showMessage("Launching BLR launcher!");
    57.  
    58. QProcess *process = new QProcess(this);
    59. process->start(path, QStringList() << "");
    60.  
    61. // Focus launcher
    62.  
    63. ui->statusBar->showMessage("Waiting for patch to finish...");
    64.  
    65. /*while True:
    66.   ImageGrab.grab().save("haystack.png")
    67.   if detectImage():
    68.   break
    69.   else:
    70.   time.sleep(3)*/
    71.  
    72. ui->statusBar->showMessage("Shutting PC down in 60 seconds! Exit this program to abort.");
    73.  
    74. /*time.sleep(60)
    75.   subprocess.Popen(['shutdown', '-s', '-t', '0'])*/
    76. }
    To copy to clipboard, switch view to plain text mode 

    As you can see from the code above (read the last 4 lines), I have a process that is started. I want to make sure that the window that starts (by that process) is focused.

    I know there is this function: http://qt-project.org/doc/qt-4.8/qap...etActiveWindow

    It requires a QWidget as a parameter. Maybe I need to convert QProcess to Qwidget?
    Last edited by tahayassen; 31st March 2013 at 03:37.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set window to active window based on QProcess?

    I am not sure what you mean. Do you want to activate a window of your first application or a window of the second application (the one started by QProcess)?

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 9th November 2011, 05:31
  2. Replies: 0
    Last Post: 4th October 2011, 16:34
  3. Replies: 0
    Last Post: 4th March 2011, 20:18
  4. Qt Designer Change active .ui file || Show a second window
    By MrRump in forum Qt Tools
    Replies: 4
    Last Post: 5th June 2010, 20:57
  5. Window Active
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2009, 12:12

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.