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. I need to get title of webpage

I need to get title of webpage

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 3 Posters 7.6k 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.
  • A Offline
    A Offline
    Armin
    wrote on last edited by
    #11

    My maintance tool problem solved.
    but i dont know how i must get title of a html page.

    jsulmJ 1 Reply Last reply
    0
    • A Armin

      My maintance tool problem solved.
      but i dont know how i must get title of a html page.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #12

      @Armin You mean you want to extract title from:

      <head>
      	<title>General and Desktop | Qt Forum</title>
      

      right?
      Then you can just sent a GET request using http://doc.qt.io/qt-5/qnetworkaccessmanager.html and then parse the response (you can use a regular expression to extract the title from <title>...</title>).
      From the link above:

      QNetworkRequest request;
      request.setUrl(QUrl("http://qt-project.org"));
      request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
      
      QNetworkReply *reply = manager->get(request);
      connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
      connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
              this, SLOT(slotError(QNetworkReply::NetworkError)));
      connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
              this, SLOT(slotSslErrors(QList<QSslError>)));
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Armin You mean you want to extract title from:

        <head>
        	<title>General and Desktop | Qt Forum</title>
        

        right?
        Then you can just sent a GET request using http://doc.qt.io/qt-5/qnetworkaccessmanager.html and then parse the response (you can use a regular expression to extract the title from <title>...</title>).
        From the link above:

        QNetworkRequest request;
        request.setUrl(QUrl("http://qt-project.org"));
        request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
        
        QNetworkReply *reply = manager->get(request);
        connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
                this, SLOT(slotError(QNetworkReply::NetworkError)));
        connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
                this, SLOT(slotSslErrors(QList<QSslError>)));
        
        A Offline
        A Offline
        Armin
        wrote on last edited by
        #13

        @jsulm Thanks
        But i want to get title and i don't need to set. i need get and no set

        jsulmJ 1 Reply Last reply
        0
        • A Armin

          @jsulm Thanks
          But i want to get title and i don't need to set. i need get and no set

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #14

          @Armin Where did I say anything about set?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Armin Where did I say anything about set?

            A Offline
            A Offline
            Armin
            wrote on last edited by Armin
            #15

            @jsulm Thanks
            In this line if i am not mistaken you set the title
            request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
            But i want to store the title in a QString

            jsulmJ 1 Reply Last reply
            0
            • A Armin

              @jsulm Thanks
              In this line if i am not mistaken you set the title
              request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
              But i want to store the title in a QString

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #16

              @Armin No this line does not set any titles, why do you think so? Did you read the documentation? You can remove this line. It is not needed for your use-case.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              3
              • jsulmJ jsulm

                @Armin No this line does not set any titles, why do you think so? Did you read the documentation? You can remove this line. It is not needed for your use-case.

                A Offline
                A Offline
                Armin
                wrote on last edited by
                #17

                @jsulm Thanks

                now , all i want is to get url in title ( <title> ... </title> ) and put it on QString.

                jsulmJ 1 Reply Last reply
                0
                • A Armin

                  @jsulm Thanks

                  now , all i want is to get url in title ( <title> ... </title> ) and put it on QString.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #18

                  @Armin You can use a regular expression after you got the response from the server to extract the title.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Armin You can use a regular expression after you got the response from the server to extract the title.

                    A Offline
                    A Offline
                    Armin
                    wrote on last edited by
                    #19

                    @jsulm Thanks
                    If that file isn't html , and be mp4 or pdf
                    So what do i do ?

                    jsulmJ 1 Reply Last reply
                    0
                    • A Armin

                      @jsulm Thanks
                      If that file isn't html , and be mp4 or pdf
                      So what do i do ?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #20

                      @Armin Sorry, but you asked how to get the title of a web page, right?
                      What do you want to do with mp4 or pdf?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @Armin Sorry, but you asked how to get the title of a web page, right?
                        What do you want to do with mp4 or pdf?

                        A Offline
                        A Offline
                        Armin
                        wrote on last edited by
                        #21

                        @jsulm Thanks
                        Right , i asked about webpage
                        How can i name of download file?
                        Thanks

                        jsulmJ 1 Reply Last reply
                        0
                        • A Armin

                          @jsulm Thanks
                          Right , i asked about webpage
                          How can i name of download file?
                          Thanks

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by jsulm
                          #22

                          @Armin The name of the file you're downloading is already in the URL, isn't it? Usually you know it in advance.
                          Like: http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run
                          File name is: qt-unified-linux-x64-online.run
                          Or do you want to know which files you can download from a web site? Then look for for something like:

                          <a href="http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run">Qt Online Installer for Linux (64-bit)</a>
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A 1 Reply Last reply
                          2
                          • jsulmJ jsulm

                            @Armin The name of the file you're downloading is already in the URL, isn't it? Usually you know it in advance.
                            Like: http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run
                            File name is: qt-unified-linux-x64-online.run
                            Or do you want to know which files you can download from a web site? Then look for for something like:

                            <a href="http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run">Qt Online Installer for Linux (64-bit)</a>
                            
                            A Offline
                            A Offline
                            Armin
                            wrote on last edited by
                            #23

                            @jsulm Thanks
                            I find answer. i use QUrl

                            1 Reply Last reply
                            0

                            • Login

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