Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:03:28+00:00 2026-06-15T15:03:28+00:00

Linux seems to be easy: xdg-open <file/directory/URL> . Apparently, Mac is similar: open should

  • 0

Linux seems to be easy: xdg-open <file/directory/URL>.

Apparently, Mac is similar: open should be used instead of xdg-open. I don’t have access to a Mac so I couldn’t test it.

For Windows, I found 4 different suggestions and those that I have tried failed.

  • Is there a non-java, cross platform way to launch the associated application for a certain file type?
    suggests
    start

  • How to give focus to default program of shell-opened file, from Java? suggests
    cmd /c start ...

  • How to open user system preferred editor for given file?
    How to Find Out Default File Opener with Java?
    suggest
    RUNDLL32.exe

  • What is the correct way to use ShellExecute() in C to open a .txt
    Open file with Windows' native program within C++ code
    How to use ShellExecute to open html files in Windows using C++? suggest
    ShellExecute

I have tried the first 3 with system() and QProcess::startDetached() and "http://www.stackoverflow.com" as argument but they all failed; start works just fine from the command line though. I haven’t tried ShellExecute yet.

What is the Windows equivalent of xdg-open? It seem to me, it is start but why did my attempts with start fail?

Is ShellExecute my only option?


EDIT I thought QDesktopServices::openUrl() was for web pages only because it did not work for files or directories.

After some debugging I figured out that if I replace \\ with / in the path on Windows, it works for files but the directories are still not opened. Any ideas what I am doing wrong?

QDir dir("C:/Documents and Settings/ali");

qDebug() << "Exists? " << dir.exists();

qDebug() << dir.absolutePath();

QDesktopServices::openUrl(QUrl(dir.absolutePath()));

qDebug() << "External app called";

Application Output:

Exists?  true 
"C:/Documents and Settings/ali" 
External app called 

But nothing happens, the directory is not opened. On Linux, directories are opened with the default file manager as expected.


SOLUTION: Due to the Qt bug and Windows quirks (malformed application window), I ended up using ShellExecute. That gives me enough flexibility to achieve exactly what I want at some expense…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:03:29+00:00Added an answer on June 15, 2026 at 3:03 pm

    Why don’t you just use Qt’s support for this? For example:

    QDesktopServices::openUrl(QUrl("/home/realnc/test.pdf"));
    

    This opens the document in Acrobat Reader. In general, it obeys the preferred application settings in my OS for all file types that have one or more applications associated with them. Best of all, it’s platform-independent.

    Edit:
    The fact that it opens directories on Linux but not on Windows smells like a bug. It might be best to report this on Qt’s bug tracker. In the meantime, you could have a workaround for Windows for when the file is a directory:

    #ifdef Q_WS_WIN
        if (QFileInfo(path).isDir())
            QProcess::startDetached("explorer", QStringList(path));
        else
    #endif
            QDesktopServices::openUrl(QUrl(path));
    

    You can also do it with cmd.exe’s start command, but you’ll get an ugly terminal pop up for a few fractions of a second:

    QProcess::startDetached("cmd", QStringList() << "/C" << "start"
                                   << QDir::toNativeSeparators(path));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After looking at RescueTime for windows/mac, it seems that there's a version for linux
This seems easy in Linux, but I'm trying to print the names of *.pdf
It seems that both git and mercurial are rather Linux oriented. Which of them
The http://code.google.com/p/pywebkitgtk/ looks great but it seems to be running on linux only. Does
Are there locks in Linux where the waiting queue is FIFO? This seems like
I'm having some trouble with distributing my python programs. for linux it's easy enough,
I have seen this http://kaasxxx.wordpress.com/2008/01/22/linux-hz-checker/ But the script seems not to work. Does anyway
In Linux, I have a rather large file with some extraneous information tacked on
I was wondering if Linux sees a difference between mmap to a peripheral devices
I am on Linux, obviously. PHP scripts seem to be running under 'www-data' user.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.