Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to open a .txt file directly by clicking on a label
Forum Updated to NodeBB v4.3 + New Features

How to open a .txt file directly by clicking on a label

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • FranciscoSantiagoF Offline
    FranciscoSantiagoF Offline
    FranciscoSantiago
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • cfdevC Offline
      cfdevC Offline
      cfdev
      wrote on last edited by
      #2

      Yes you can do this with QDesktopServices::openUrl.

      FranciscoSantiagoF 1 Reply Last reply
      2
      • cfdevC cfdev

        Yes you can do this with QDesktopServices::openUrl.

        FranciscoSantiagoF Offline
        FranciscoSantiagoF Offline
        FranciscoSantiago
        wrote on last edited by
        #3

        @cfdev

        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 ;)

        raven-worxR 1 Reply Last reply
        0
        • FranciscoSantiagoF FranciscoSantiago

          @cfdev

          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 ;)

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @FranciscoSantiago

          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);
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved