Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to run an exe file on a second monitor
I'm working on an application which has to run in a PC with two screens.
The program executes an external exe file with QProcess. The main interface of my program has to go on the first screen and the QProcess/exe file has to go on the second screen. How can I do it? Have I to bind QProcess with a QWidget object?
Thanks in advance
Depends on how that second program, which you run via QProcess, creates its GUI window. If that program just creates its window on the "primary" screen, then there probably isn't much you can do about that. If the second program is under your control (i.e. you have access to the code), have a look at QDesktopWidget::screenGeometry(n). Just grab the screen you which (by specifying the right index) and then move your window there...
@const int n = QApplication::desktop()->screenCount();
for(int i = 0; i < n; i++)
QRect w = QApplication::desktop()->screenGeometry(i);
qDebug("Screen %d: (%d,%d) -> %d x %d",
i, w.x(), w.y(), w.width(), w.height());
BTW: I think it's also possible to move windows that belong to another process. But this will probably involve some platform-specific code for obtaining a handle to that window and finally moving it around.
I have done it using win32 api. I want do it now using QT. I would like simply move the the GUI of the exe or encapsulate it in an object which i can manage.
Again: If the window you want to move belongs to the second process, it can only be (easily) moved from with that process. Unless you have the code of the second program and can modify it as needed (or the second program already exposes an option to select the screen), this won't be possible to achieve from the first process, except for using the Win32 API directly.
Using the Win32 API is more a "hack", but in theory you should be able to grab the handle of the second process' window - from the first process - by using EnumWindows. Then you can move it via SetWindowPos function.
Thanks for the suggestions.
I don't have the code of the exe and i don't know how to use QProcess to move the GUI of the exe from the main screen to the second one.
Sorry for boring questions...
I'm pretty sure QProcess can not do that and was never intended to do that. Only exception would be when the program, that you are about to run, exposes a command-lin switch to select the screen. In that specific case, QProcess could pass the required argument. Otherwise, I don't think you can move the window, which belongs to another process, purely with Qt code.