Notices


Reply
Thread Tools
Posts: 2,067 | Thanked: 3,469 times | Joined on Apr 2010 @ St. Helens, England
#1
I'd like to announce Ten Minute Core Workout.

All information on the wiki page.
Attached Images
    
__________________
The stable-beast currently runs...
21.2011.38-1Smaemo6.1 (CSSU Stable)
2.6.28.10power52 (125-600Mhz SR VDD1&2)

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.

Last edited by sixwheeledbeast; 2014-04-26 at 15:32. Reason: Updated to 0.0.8
 

The Following 15 Users Say Thank You to sixwheeledbeast For This Useful Post:
Posts: 132 | Thanked: 79 times | Joined on Mar 2012 @ Russia
#2
Please, place here screenshots of program Ten Minute Core Workout!
 
Posts: 2,067 | Thanked: 3,469 times | Joined on Apr 2010 @ St. Helens, England
#3
Done.
It's not the most exciting screenshot ever.

Can anybody help with my buttons, would there be a reason why these slots would not work?

Code:
void MainWindow::on_pushButtonStart_clicked()
{
    QProcess process;
    process.start("sh /opt/tenminutecore/script/tenminutecore.sh");
}

void MainWindow::on_pushButtonStop_clicked()
{
    QProcess process;
    process.start("sh /opt/tenminutecore/script/kill.sh");
    process.waitForFinished();
}
__________________
The stable-beast currently runs...
21.2011.38-1Smaemo6.1 (CSSU Stable)
2.6.28.10power52 (125-600Mhz SR VDD1&2)

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.
 

The Following 4 Users Say Thank You to sixwheeledbeast For This Useful Post:
Posts: 1,343 | Thanked: 3,571 times | Joined on Dec 2010 @ Dayton, Ohio
#4
Hmm, not sure why that wouldn't be working; it looks exactly like what the Qt documentation says for QProcess.

Maybe there's some sort of permissions problem?

There could also be some issue with how the argument is being passed to the shell, I suppose. You might try creating a shell script instead, i.e.:

Code:
#!/bin/sh

/opt/tenminutecore/script/tenminutecore.sh
(Assuming that tenminutecore.sh isn't already an executable shell script itself.) Then make it executable, and just use the script name instead:

Code:
process.start("yourscriptname.sh");
If all else fails, you can always fall back to using the good old fork/exec mechanism:

Code:
  pid_t pid = fork();

  if (pid == 0)
  {
    // We're inside the child process
    execl(
      "/bin/sh",
      "/bin/sh",
      "/opt/tenminutecore/script/tenminutecore.sh",
      NULL);
  }

  // If we reach this point, we are inside the parent process.
  // So, we'll wait for the child process to complete:
  int *stat_loc = NULL;
  waitpid(pid, stat_loc, 0);
Not portable to non-linux systems the way that QProcess is, but I can at least say that this works fine in Pierogi.

EDIT: There is apparently an "error()" signal for the QProcess object that gets sent if the call to "start()" fails. Maybe connecting that to a slot to see what it says will provide a bit more info as to what is going on...

Last edited by Copernicus; 2012-10-19 at 20:02. Reason: Qt also provides an error() signal
 

The Following 3 Users Say Thank You to Copernicus For This Useful Post:
Posts: 2,067 | Thanked: 3,469 times | Joined on Apr 2010 @ St. Helens, England
#5
@Copernicus Thanks for the ideas.

Seems changing to this did the trick (pinched from Theme Customizer)
No idea why the first version didn't work.

Code:
void MainWindow::on_pushButtonStart_clicked()
{
    QProcess *process;
            process = new QProcess( this );
            process->start("sh opt/tenminutecore/script/tenminutecore.sh");
}

void MainWindow::on_pushButtonStop_clicked()
{
    QProcess *process;
            process = new QProcess( this );
            process->start("sh opt/tenminutecore/script/kill.sh");
            process->waitForFinished();
}
Just require some testers now.

Finally what's the best way to go about implementing portrait support?
Ideally I just require the stop button to move below the start in portrait.
__________________
The stable-beast currently runs...
21.2011.38-1Smaemo6.1 (CSSU Stable)
2.6.28.10power52 (125-600Mhz SR VDD1&2)

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.
 

The Following 3 Users Say Thank You to sixwheeledbeast For This Useful Post:
Posts: 1,343 | Thanked: 3,571 times | Joined on Dec 2010 @ Dayton, Ohio
#6
Originally Posted by sixwheeledbeast View Post
Seems changing to this did the trick (pinched from Theme Customizer)
No idea why the first version didn't work.
It might be that QProcess needed to have the parent object specified. (Or maybe the fact that the Qt guys are in love with the model-view-controller paradigm, and therefore want everything allocated on the heap rather than the stack. I'm not a huge fan of MVC architecture...) Good to see that it's working, though!

I can't help much with properly supporting portrait mode, but you probably knew that already.
 

The Following 3 Users Say Thank You to Copernicus For This Useful Post:
marxian's Avatar
Posts: 2,358 | Thanked: 8,746 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
}
__________________
Its already dog-eat-dog, friend. Im not sure what worse a bunch of zombies could do.

My website

GitHub
 

The Following 8 Users Say Thank You to marxian For This Useful Post:
sifo's Avatar
Posts: 1,359 | Thanked: 1,288 times | Joined on Oct 2011 @ Tartus.Syria
#8
What about moving this thread to Development section ?
__________________
[ N900-Crack ] [ The Purge ] [ New Smiles ] [ New icons ] [ ? ]
" Hey ! I've just met you and this is crazy, so install cssu maybe ? "
Please help out keeping Maemo.org alive, and consider donating.
https://www.facebook.com/ZoRk7
 
Posts: 1,343 | Thanked: 3,571 times | Joined on Dec 2010 @ Dayton, Ohio
#9
Originally Posted by marxian View Post
Your old approach didn't work because the QProcess object fell out of scope.
Ah! So a "StartDetached()" call would work in that case, allowing the script to continue after the QProcess object is destroyed.

Actually, this also means you don't really need the "kill.sh" script to stop the process (unless kill.sh does something special). A call to "terminate()" (or just destroying the object) should do the trick...

EDIT: As Marxian notes below, you can't call "terminate()" on a destroyed QProcess object. (In short, you'd need to have a QProcess object that lives beyond the start_clicked() method, call "start()" (not "startDetached()") on it in that method, and call "terminate()" in the stop_clicked() method...)

Last edited by Copernicus; 2012-10-20 at 00:01. Reason: Edit: oops, thanks for Marxian fix
 

The Following 2 Users Say Thank You to Copernicus For This Useful Post:
marxian's Avatar
Posts: 2,358 | Thanked: 8,746 times | Joined on Aug 2010 @ Wigan, UK
#10
Originally Posted by Copernicus View Post
Ah! So a "StartDetached()" call would work in that case, allowing the script to continue after the QProcess object is destroyed.

Actually, this also means you don't really need the "kill.sh" script to stop the process (unless kill.sh does something special). A call to "terminate()" (or just destroying the object) should do the trick...
startDetached() will work, yes, because it's a static method. The disadvantage is that you don't have access to the QProcess object after the method is called. Another alternative is to call waitForFinished() after calling start(), which enables synchronous (blocking) use of QProcess. That way you can use a QProcess object with local scope, because there is no further event processing until the start() method returns. This approach has the disadvantage of blocking the main thread until the program called by QProcess exits. Synchronous use of QProcess is really only useful for cases where there is no event loop. I can't see any reason to use it where you have a QApplication instance.
__________________
Its already dog-eat-dog, friend. Im not sure what worse a bunch of zombies could do.

My website

GitHub

Last edited by marxian; 2012-10-20 at 00:00.
 

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

Tags
bouldering, exercise, tenminutecore, training

Thread Tools

 
Forum Jump


All times are GMT. The time now is 06:17.