0

Hi I have written an application in QT, which is supposed to execute a script, written already on ubuntu 14.04, but its not performing the function as desired. This is the piece of code which I have written.

void MainWindow::on_pushButton_clicked()
{
    QProcess process ;
    process.startDetached("/bin/bash", QStringList() << "path to file.sh");
}

What I am missing here? Thanx for valuable suggestions.

7
  • Does the .sh file do? Commented Jan 19, 2017 at 5:33
  • @eyllanesc yes, the .sh file executes and perform all the functionality if i run it manually on terminal. Commented Jan 19, 2017 at 5:37
  • I've tried your code and I have not had any problems. file.sh: #!/bin/sh mkdir test Commented Jan 19, 2017 at 5:43
  • 1
    Does it make any difference if you allocate the QProcess on the heap (using the new operator) rather than on the stack? (It might be that the QProcess object's destructor is interfering with the running of the script) Commented Jan 19, 2017 at 5:47
  • 1
    Here's a test for you... if you temporary replace /home/randomuser/file.sh with a file that just contains this line: echo hi > /tmp/foo.txt ... and then run your Qt program again, do you see a file /tmp/foo.txt afterwards? If so, you know the script ran, and it must be something in your particular file.sh that doesn't like executing in a non-interactive terminal. Commented Jan 19, 2017 at 6:17

1 Answer 1

1

I found the mistake, actually the code works well. When i press the button the GUI creates a new file in the same directory, but i have written the script in home directory. So i was expecting the new file in home directory, but it was already there in project directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.