1

I am creating an GUI application using QT creater in Raspbian. When I click a button I want to open an external application like terminal, or browser, etc.

I have tried many attempts

  • attempt 1
std::system("/usr/share/raspi-ui-overrides/applications/scratch.desktop&");

it says me permission denied

  • attempt 2
QDesktopServices::openUrl(QUrl("/usr/share/raspi-ui-overrides/applications/scratch.desktop"));
  • this one is working but its not opening the application but its opening in terminal:
QDesktopServices::openUrl(QUrl("/usr/share/raspi-ui-overrides/applications/scratch.desktop"));
2
  • show the content of scratch.desktop Commented May 28, 2019 at 5:15
  • Are you able to execute /usr/share/raspi-ui-overrides/applications/scratch.desktop& from a terminal? Commented May 28, 2019 at 5:17

2 Answers 2

1

I'm assuming the question is about Raspberry Pi and Raspbian.

In Raspbian, the scratch.desktop and other *.desktop files are not executables, but just text files that describe which application to run.

Example:

pi@raspberrypi:~ $ cat /usr/share/raspi-ui-overrides/applications/scratch.desktop 
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
TryExec=scratch
Exec=scratch
Icon=scratch
Terminal=false
Name=Scratch
Comment= Programming system and content development tool
Categories=Application;Development;
MimeType=application/x-scratch-project

You need to use an actual binary to start the process. For scratch, it would be /usr/bin/scratch. For a browser, it's likely to be /usr/bin/epiphany-browser. Look at Exec= line in the *.desktop file to see the name of the executable, then use which in the terminal to see its location:

pi@raspberrypi:~ $ which epiphany-browser 
/usr/bin/epiphany-browser
Sign up to request clarification or add additional context in comments.

7 Comments

Hi I have tried using this path /usr/bin/scratch still the application is not opening
Does it work if you run /usr/bin/scratch in the terminal?
Also, it's not QDesktopServices::openUrl, it's more likely QProcess::execute as @eyllanesc suggests.
@MohdViquar use QProcess::startDetached("/usr/bin/scratch");
hi yes its working when I use /usr/bin/scratch on qprocess::execute command how to find the location of other application? thanks
|
1

The .desktop files are not executable, but serve as shortcuts for the desktop system. Assuming that the scratch.desktop has the following:

scratch.desktop

[Desktop Entry]
Name=Scratch
Comment= Programming system and content development tool
Exec=scratch
Terminal=false
Type=Application
Icon=scratch
Categories=Development;
MimeType=application/x-scratch-project

Then the executable is /usr/bin/scratch, And you can run it with Qt:

QProcess::startDetached("/usr/bin/scratch");

Or:

QProcess::execute("/usr/bin/scratch");

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.