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 want to get file from server

I want to get file from server

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 3.4k Views 2 Watching
  • 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
    #1

    Hi
    I want to get file from server ( download )
    I write this code and get error:

    void MainWindow::on_pushButton_clicked()
    {
    QNetworkAccessManager downloadmanager;
    QNetworkRequest dl2;
    downloadmanager.get(dl2.setUrl(ui->textEdit->toPlainText.toString()));
    }
    

    error: '((MainWindow*)this)->MainWindow::ui->Ui::MainWindow::<anonymous>.Ui_MainWindow::textEdit->QTextEdit::toPlainText' does not have class type
    downloadmanager.get(dl2.setUrl(ui->textEdit->toPlainText.toString()));
    ^

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Armin
      wrote on last edited by
      #2

      I change my code but get error again :(

      void MainWindow::on_pushButton_clicked()
      {
      QNetworkAccessManager downloadmanager;
      QNetworkRequest dl2;
      t = ui->textEdit->toPlainText();
      downloadmanager.get(dl2.setUrl(QUrl::url(t)));
      }
      
      
      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Hi! void QNetworkRequest::setUrl(const QUrl &url) returns void, but QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request) takes a const QNetworkRequest &.

        1 Reply Last reply
        3
        • A Offline
          A Offline
          Armin
          wrote on last edited by
          #4

          Thanks @Wieland
          I get error from this code:

          void MainWindow::on_pushButton_clicked()
          {
          t = ui->textEdit->toPlainText();
          QNetworkAccessManager::get(QNetworkRequest::setUrl(QUrl::url()));
          }
          
          

          C:\Users\armin\Documents\DownloadManager\mainwindow.cpp:22: error: cannot call member function 'QString QUrl::url(QUrl::FormattingOptions) const' without object
          QNetworkAccessManager::get(QNetworkRequest::setUrl(QUrl::url()));
          ^

          jsulmJ 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You are calling a normal function as it was static. You need to have a QUrl object if you want to call the url method on it.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • A Armin

              Thanks @Wieland
              I get error from this code:

              void MainWindow::on_pushButton_clicked()
              {
              t = ui->textEdit->toPlainText();
              QNetworkAccessManager::get(QNetworkRequest::setUrl(QUrl::url()));
              }
              
              

              C:\Users\armin\Documents\DownloadManager\mainwindow.cpp:22: error: cannot call member function 'QString QUrl::url(QUrl::FormattingOptions) const' without object
              QNetworkAccessManager::get(QNetworkRequest::setUrl(QUrl::url()));
              ^

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

              @Armin said in I want to get file from server:

              QNetworkRequest

              As @Wieland already told you setUrl() does not return anything. But QNetworkAccessManager::get() expects a QNetworkRequest.
              And as @SGaist said calling QUrl::url() is just wrong as url() is not static (and what do you actually expect it to return?).
              Why not just

              void MainWindow::on_pushButton_clicked()
              {
              QNetworkAccessManager *downloadmanager = new QNetworkAccessManager(this);
              QNetworkRequest dl2;
              t = ui->textEdit->toPlainText();
              dl2.setUrl(QUrl::url(t));
              downloadmanager.get(dl2);
              }
              

              You should allocate QNetworkAccessManager on the heap via new because else it will disappear as soon as on_pushButton_clicked() finishes. Important: downloadmanager.get(dl2) is asynchronous! You should really read the documentation.

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

              1 Reply Last reply
              1
              • A Offline
                A Offline
                Armin
                wrote on last edited by
                #7

                Thanks @SGaist and Thanks @jsulm
                @jsulm I put your and replace with my code but i get error:

                C:\Users\armin\Documents\DownloadManager\mainwindow.cpp:22: error: no matching function for call to 'QUrl::url(QString&)'
                dl2.setUrl(QUrl::url(t));
                ^

                C:\Users\armin\Documents\DownloadManager\mainwindow.cpp:23: error: request for member 'get' in 'downloadmanager', which is of pointer type 'QNetworkAccessManager*' (maybe you meant to use '->' ?)
                downloadmanager.get(dl2);
                ^

                jsulmJ 1 Reply Last reply
                0
                • A Armin

                  Thanks @SGaist and Thanks @jsulm
                  @jsulm I put your and replace with my code but i get error:

                  C:\Users\armin\Documents\DownloadManager\mainwindow.cpp:22: error: no matching function for call to 'QUrl::url(QString&)'
                  dl2.setUrl(QUrl::url(t));
                  ^

                  C:\Users\armin\Documents\DownloadManager\mainwindow.cpp:23: error: request for member 'get' in 'downloadmanager', which is of pointer type 'QNetworkAccessManager*' (maybe you meant to use '->' ?)
                  downloadmanager.get(dl2);
                  ^

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

                  @Armin Well, QUrl does not have a get() method, you just use the constructor (that's why a said you should read documentation):

                  dl2.setUrl(QUrl(t));
                  

                  The second error message actually tells you what is wrong:

                  downloadmanager->get(dl2);
                  

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

                  1 Reply Last reply
                  1
                  • A Offline
                    A Offline
                    Armin
                    wrote on last edited by
                    #9

                    Really thanks @jsulm

                    I don't have any error but i replace this code with your code and i don't get error , My new code isn't wrong?

                    void MainWindow::on_pushButton_clicked()
                    {
                        QNetworkAccessManager downloadmanager;
                    
                    QNetworkRequest dl2;
                    t = ui->textEdit->toPlainText();
                    dl2.setUrl(QUrl(t));
                    downloadmanager.get(dl2);
                    }
                    
                    jsulmJ 2 Replies Last reply
                    0
                    • A Armin

                      Really thanks @jsulm

                      I don't have any error but i replace this code with your code and i don't get error , My new code isn't wrong?

                      void MainWindow::on_pushButton_clicked()
                      {
                          QNetworkAccessManager downloadmanager;
                      
                      QNetworkRequest dl2;
                      t = ui->textEdit->toPlainText();
                      dl2.setUrl(QUrl(t));
                      downloadmanager.get(dl2);
                      }
                      
                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Armin Are you aware that downloadmanager will be destroyed as soon as void MainWindow::on_pushButton_clicked() terminates? I already said that you should allocate it on the heap using new. downloadmanager.get(dl2) is assynchronous - that means the result will be available later, after downloadmanager.get(dl2) finishes.
                      Do it like this:

                      QNetworkAccessManager *downloadmanager = new QNetworkAccessManager(this);
                      

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

                      1 Reply Last reply
                      1
                      • A Armin

                        Really thanks @jsulm

                        I don't have any error but i replace this code with your code and i don't get error , My new code isn't wrong?

                        void MainWindow::on_pushButton_clicked()
                        {
                            QNetworkAccessManager downloadmanager;
                        
                        QNetworkRequest dl2;
                        t = ui->textEdit->toPlainText();
                        dl2.setUrl(QUrl(t));
                        downloadmanager.get(dl2);
                        }
                        
                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Armin And how do you want to get the result? Currently you do not connect any slots to the signals. You will need http://doc.qt.io/qt-5/qnetworkaccessmanager.html#finished

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

                        1 Reply Last reply
                        1
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          To add to @jsulm, make your downloadmanager a member of MainWindow and initialise it in your constructor, otherwise you are going to uselessly create new QNetworkAccessManager.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1

                          • Login

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