Hi! I think your file path is wrong. Try my solution:
Qt Code:
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath() + "/docs/" + "nameof.pdf"));To copy to clipboard, switch view to plain text mode
Hi! I think your file path is wrong. Try my solution:
Qt Code:
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath() + "/docs/" + "nameof.pdf"));To copy to clipboard, switch view to plain text mode
tndave (7th August 2018)
Defensive programming tip: Always create a local QString variable to hold the result of expressions like
Qt Code:
qApp->applicationDirPath() + "/docs/" + "nameof.pdf"To copy to clipboard, switch view to plain text mode
so that when things don't work as expected, you can look at the contents of the QString in the debugger or a QMessageBox in release mode and verify that the string actually contains the path you expect.
The environment that gets set up when you run in the debugger vs. running standalone from the command line (or an icon click from the desktop) often leads to unexpected values for paths. If you simply build a string and pass it directly into a method, you don't really have any good way of examining that string to figure out what's wrong.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
tndave (7th August 2018)
Bookmarks