View Single Post
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#7
Your old approach didn't work because the QProcess object fell out of scope. Your second approach seems to result in a memory leak, since you are creating new QProcess objects when the buttons are pressed, without deleting them until the MainWindow object is deleted (since that is the parent). The best solution will be to make it a private member of MainWindow:

Code:
private:
    QProcess *m_process;
Instantiate it in the MainWindow constructor (and connect to its signals for error checking if you want) and you can use the same QProcess object to launch the scripts.

For portrait support, you can connect to the resized() signal of QDesktopWidget and adjust the geometry of your widgets as you require.

Code:
#include <QApplication>
#include <QDesktopWidget>

...

connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onOrientationChanged()));

...

void MainWindow::onOrientationChanged() {
   QRect screen = QApplication::desktop()->screenGeometry();

    if (screen.width() > screen.height()) {
        setLandscapeLayout();
    }
    else {
        setPortraitLayout();
    }
}

void MainWindow::setLandscapeLayout() {
   do stuff
}

void MainWindow::setPortraitLayout() {
   do stuff
}
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 

The Following 8 Users Say Thank You to marxian For This Useful Post: