Unsolved How to open a .txt file directly by clicking on a label
-
Hi all,
maybe this is a stupid issue, but I've been searching the solution on Internet since two hours and now I'm fed up and I ask to you.I have a Qlabel. When I click it (by using the slot linkActivated I suppose) I want to directly open a .txt file in my PC.
Is this doable? Who can help me? Please let me know the proper instructions.
-
Yes you can do this with QDesktopServices::openUrl.
-
Hi, Thank you for reply.
Could you be more precise? Have you got an example ?How can I set the label, link, url, QDesktopService, and so on... ?
Thank you ;)
-
QLabel* label = new QLabel("<a href=\"file:///path/to/my/local/file\">Any text or file path</a>"); connect( label, SIGNAL(linkActivated(QString)), this, SLOT(onLabelLinkClicked(QString)) ); ... void onLabelLinkClicked(const QString & link) { QUrl url = QUrl::fromUserInput(link); if( url.isValid() ) QDesktopServices::openUrl(url); }