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. String Split
Qt 6.11 is out! See what's new in the release blog

String Split

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 7 Posters 3.4k Views 1 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.
  • jondoeJ Offline
    jondoeJ Offline
    jondoe
    wrote on last edited by
    #1

    Hello,

    I with this code can download dll from url and can save to system32.

    HRESULT hr;
          LPCTSTR Url = _T("http://sitename.com/dlls/dllname.dll"), File = _T("C:\\Users\\user\\Desktop\\testfile\\dllname.dll");
          hr = URLDownloadToFile (0, Url, File, 0, 0);
          switch (hr)
              {
                  case S_OK:
                      qDebug() << "Successful download\n";
                      break;
                  case E_OUTOFMEMORY:
                      qDebug() << "Out of memory error\n";
                      break;
                  case INET_E_DOWNLOAD_FAILURE:
                      qDebug() << "Cannot access server data\n";
                      break;
                  default:
                      qDebug() << "Unknown error\n";
                      break;
              }
    

    But I have php file and I getting text of this file and strings like this.

    dllname1.dll,dllname2dll,

    First I need to split this string with " , ". After that I need to get name of dll's and download all dll to system32 with while.
    How can I do this ?

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

      Hi,

      For splitting: QString::split. As for moving your .dll there, you would have first to gain admin rights. In any case, it's always a bad idea to put application related .dlls in system32.

      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
      5
      • jondoeJ Offline
        jondoeJ Offline
        jondoe
        wrote on last edited by
        #3

        Somebody can help me please I dont know how can I code this split and loop :(

        aha_1980A 1 Reply Last reply
        0
        • jondoeJ jondoe

          Somebody can help me please I dont know how can I code this split and loop :(

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @jondoe

          QString files = "test1.dll,test2.dll,test3.dll";
          const QStringList list = files.split(',');
          for (const QString &name : list {
            qDebug() << name;
          }
          

          Qt has to stay free or it will die.

          jondoeJ 1 Reply Last reply
          3
          • aha_1980A aha_1980

            Hi @jondoe

            QString files = "test1.dll,test2.dll,test3.dll";
            const QStringList list = files.split(',');
            for (const QString &name : list {
              qDebug() << name;
            }
            
            jondoeJ Offline
            jondoeJ Offline
            jondoe
            wrote on last edited by
            #5

            @aha_1980

            How can I use this with download function ?

            Gojir4G aha_1980A 2 Replies Last reply
            0
            • jondoeJ jondoe

              @aha_1980

              How can I use this with download function ?

              Gojir4G Offline
              Gojir4G Offline
              Gojir4
              wrote on last edited by
              #6

              @jondoe said in String Split:

              @aha_1980

              How can I use this with download function ?

              for (const QString &name : list {
                downloadFile(name);
              }
              
              jondoeJ 1 Reply Last reply
              0
              • jondoeJ jondoe

                @aha_1980

                How can I use this with download function ?

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by aha_1980
                #7

                @jondoe

                Try this:

                QString dlls = "test1.dll,test2.dll,test3.dll";
                const QStringList list = dlls.split(',');
                
                for (const QString &name : list) {
                  const QString url = QString("http://sitename.com/dlls/") + name;
                  const QString file = QString("C:\\Users\\user\\Desktop\\testfile\\") + name;
                  qDebug() << "Downloading" << url << "to" << file << "...";
                  HRESULT hr = URLDownloadToFileW(0, (LPCWSTR)url.utf16(), (LPCWSTR)file.utf16(), 0, 0);
                }
                
                

                Qt has to stay free or it will die.

                jondoeJ Cobra91151C 2 Replies Last reply
                2
                • Gojir4G Gojir4

                  @jondoe said in String Split:

                  @aha_1980

                  How can I use this with download function ?

                  for (const QString &name : list {
                    downloadFile(name);
                  }
                  
                  jondoeJ Offline
                  jondoeJ Offline
                  jondoe
                  wrote on last edited by jondoe
                  #8

                  @Gojir4

                  I tried like this but I got error.

                  QString getdlls = "http://sitename/dlls.php";
                    QByteArray dllssonuc = QResolveUrl(getdlls);
                  
                    //qDebug() << "testedek" << dllssonuc;
                  
                    QString files = dllssonuc;
                    const QStringList list = files.split(',');
                    for (const QString &name : list) {
                      //qDebug() << "deneyelim" << name;
                  
                        if (name != "")
                        {
                      HRESULT hr;
                          LPCTSTR Url = _T("http://sitename.com/dlls/" + name), File = _T("C:\\Users\\user\\Desktop\\testklasor\\" + name);
                          hr = URLDownloadToFile (0, Url, File, 0, 0);
                          switch (hr)
                              {
                                  case S_OK:
                                      qDebug() << "Successful download\n";
                                      break;
                                  case E_OUTOFMEMORY:
                                      qDebug() << "Out of memory error\n";
                                      break;
                                  case INET_E_DOWNLOAD_FAILURE:
                                      qDebug() << "Cannot access server data\n";
                                      break;
                                  default:
                                      qDebug() << "Unknown error\n";
                                      break;
                              }
                          }
                  
                  
                    }
                  
                  1 Reply Last reply
                  0
                  • aha_1980A aha_1980

                    @jondoe

                    Try this:

                    QString dlls = "test1.dll,test2.dll,test3.dll";
                    const QStringList list = dlls.split(',');
                    
                    for (const QString &name : list) {
                      const QString url = QString("http://sitename.com/dlls/") + name;
                      const QString file = QString("C:\\Users\\user\\Desktop\\testfile\\") + name;
                      qDebug() << "Downloading" << url << "to" << file << "...";
                      HRESULT hr = URLDownloadToFileW(0, (LPCWSTR)url.utf16(), (LPCWSTR)file.utf16(), 0, 0);
                    }
                    
                    
                    jondoeJ Offline
                    jondoeJ Offline
                    jondoe
                    wrote on last edited by
                    #9

                    @aha_1980

                    Error like this -> invalid conversion from 'const wchar_t*' to 'char' [-fpermissive] LPCTSTR Url

                    aha_1980A 1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      TobbY
                      wrote on last edited by TobbY
                      #10

                      Hi,

                      you need to do conversion for that. please refer this code if that help.

                      Required Libs

                      #include <Windows.h>
                      #include <urlmon.h>
                      #include <Wininet.h>
                      #pragma comment(lib, "urlmon.lib")
                      #pragma comment(lib,"wininet.lib")
                      

                      To Query DLLs

                          QString data = "test1.dll,test2.dll,test3.dll";
                          QStringList list = data.split(",");
                          for (const QString &name : list ) {
                              if (name != "") downloadFile(name);
                          }
                      

                      To Download DLL

                      void MainWindow::downloadFile(QString name)
                      {
                          HRESULT hr;
                          LPCTSTR Url = (LPTSTR)QString("http://sitename.com/dlls/" + name).utf16(); // Convert QString to LPCTSTR 
                          LPCTSTR File = (LPTSTR)QString("C:\\Users\\user\\Desktop\\testklasor\\" + name).utf16();
                          hr = URLDownloadToFile (0, Url, File, 0, 0);
                          switch (hr)
                          {
                          case S_OK:
                              qDebug() << "Successful download\n";
                              break;
                          case E_OUTOFMEMORY:
                              qDebug() << "Out of memory error\n";
                              break;
                          case INET_E_DOWNLOAD_FAILURE:
                              qDebug() << "Cannot access server data\n";
                              break;
                          default:
                              qDebug() << "Unknown error\n" << hr;
                              break;
                          }
                      }
                      
                      jondoeJ 1 Reply Last reply
                      1
                      • T TobbY

                        Hi,

                        you need to do conversion for that. please refer this code if that help.

                        Required Libs

                        #include <Windows.h>
                        #include <urlmon.h>
                        #include <Wininet.h>
                        #pragma comment(lib, "urlmon.lib")
                        #pragma comment(lib,"wininet.lib")
                        

                        To Query DLLs

                            QString data = "test1.dll,test2.dll,test3.dll";
                            QStringList list = data.split(",");
                            for (const QString &name : list ) {
                                if (name != "") downloadFile(name);
                            }
                        

                        To Download DLL

                        void MainWindow::downloadFile(QString name)
                        {
                            HRESULT hr;
                            LPCTSTR Url = (LPTSTR)QString("http://sitename.com/dlls/" + name).utf16(); // Convert QString to LPCTSTR 
                            LPCTSTR File = (LPTSTR)QString("C:\\Users\\user\\Desktop\\testklasor\\" + name).utf16();
                            hr = URLDownloadToFile (0, Url, File, 0, 0);
                            switch (hr)
                            {
                            case S_OK:
                                qDebug() << "Successful download\n";
                                break;
                            case E_OUTOFMEMORY:
                                qDebug() << "Out of memory error\n";
                                break;
                            case INET_E_DOWNLOAD_FAILURE:
                                qDebug() << "Cannot access server data\n";
                                break;
                            default:
                                qDebug() << "Unknown error\n" << hr;
                                break;
                            }
                        }
                        
                        jondoeJ Offline
                        jondoeJ Offline
                        jondoe
                        wrote on last edited by
                        #11

                        @TobbY

                        Thank you for answer but debug like this.

                        Unknown error
                        -2146697211
                        Unknown error
                        -2146697211

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          TobbY
                          wrote on last edited by
                          #12

                          @TobbY said in String Split:

                          URLDownloadToFile

                          Hi,
                          Have you tried it with correct url and dlls ?

                          jondoeJ 1 Reply Last reply
                          0
                          • T TobbY

                            @TobbY said in String Split:

                            URLDownloadToFile

                            Hi,
                            Have you tried it with correct url and dlls ?

                            jondoeJ Offline
                            jondoeJ Offline
                            jondoe
                            wrote on last edited by
                            #13

                            @TobbY yes but still same error.

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              TobbY
                              wrote on last edited by TobbY
                              #14

                              Hi,
                              Please check error code. INET_E_RESOURCE_NOT_FOUND (0x800C0005L or -2146697211)

                              https://msdn.microsoft.com/en-us/library/bb268233(v=vs.85).aspx

                              1 Reply Last reply
                              0
                              • jondoeJ jondoe

                                @aha_1980

                                Error like this -> invalid conversion from 'const wchar_t*' to 'char' [-fpermissive] LPCTSTR Url

                                aha_1980A Offline
                                aha_1980A Offline
                                aha_1980
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @jondoe if you don't copy my code 1:1, you'll have to fix yourself.

                                Qt has to stay free or it will die.

                                1 Reply Last reply
                                2
                                • aha_1980A aha_1980

                                  @jondoe

                                  Try this:

                                  QString dlls = "test1.dll,test2.dll,test3.dll";
                                  const QStringList list = dlls.split(',');
                                  
                                  for (const QString &name : list) {
                                    const QString url = QString("http://sitename.com/dlls/") + name;
                                    const QString file = QString("C:\\Users\\user\\Desktop\\testfile\\") + name;
                                    qDebug() << "Downloading" << url << "to" << file << "...";
                                    HRESULT hr = URLDownloadToFileW(0, (LPCWSTR)url.utf16(), (LPCWSTR)file.utf16(), 0, 0);
                                  }
                                  
                                  
                                  Cobra91151C Offline
                                  Cobra91151C Offline
                                  Cobra91151
                                  wrote on last edited by
                                  #16

                                  @aha_1980 said in String Split:

                                  @jondoe

                                  Try this:

                                  QString dlls = "test1.dll,test2.dll,test3.dll";
                                  const QStringList list = dlls.split(',');
                                  
                                  for (const QString &name : list {
                                    const QString url = QString("http://sitename.com/dlls/") + name;
                                    const QString file = QString("C:\\Users\\user\\Desktop\\testfile\\") + name;
                                    qDebug() << "Downloading" << url << "to" << file << "...";
                                    HRESULT hr = URLDownloadToFileW(0, (LPCWSTR)url.utf16(), (LPCWSTR)file.utf16(), 0, 0);
                                  }
                                  
                                  

                                  Hi! You forgot closing ) in the for loop)).

                                  aha_1980A 1 Reply Last reply
                                  1
                                  • Cobra91151C Cobra91151

                                    @aha_1980 said in String Split:

                                    @jondoe

                                    Try this:

                                    QString dlls = "test1.dll,test2.dll,test3.dll";
                                    const QStringList list = dlls.split(',');
                                    
                                    for (const QString &name : list {
                                      const QString url = QString("http://sitename.com/dlls/") + name;
                                      const QString file = QString("C:\\Users\\user\\Desktop\\testfile\\") + name;
                                      qDebug() << "Downloading" << url << "to" << file << "...";
                                      HRESULT hr = URLDownloadToFileW(0, (LPCWSTR)url.utf16(), (LPCWSTR)file.utf16(), 0, 0);
                                    }
                                    
                                    

                                    Hi! You forgot closing ) in the for loop)).

                                    aha_1980A Offline
                                    aha_1980A Offline
                                    aha_1980
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @Cobra91151 said in String Split:

                                    Hi! You forgot closing ) in the for loop)).

                                    Psst. Don't tell anyone. It's part of the homework ;)

                                    Qt has to stay free or it will die.

                                    1 Reply Last reply
                                    1
                                    • VRoninV Offline
                                      VRoninV Offline
                                      VRonin
                                      wrote on last edited by VRonin
                                      #18

                                      If you are using Qt I don't see why you have to complicate your life using LPCTSTR and stuff like that.

                                      const QString dlls = "test1.dll,test2.dll,test3.dll";
                                      const QStringList list = dlls.split(',');
                                      QEventLoop waitLoop;
                                      int dllsToDownLoad =  list.size();
                                      auto manager = new QNetworkAccessManager;
                                      for (const QString &name : list){
                                          auto destinationFile = new QFile("C:/Users/user/Desktop/testfile/" + name);
                                          if (!destinationFile.open(QFile::WriteOnly)){
                                              --dllsToDownLoad ;
                                              continue;
                                          }
                                          QNetworkReply* reply = manager->get(QNetworkRequest(QUrl::fromUserInput("http://sitename.com/dlls/" + name)));
                                          QObject::connect(reply, &QNetworkReply::readyRead(), [destinationFile, reply]() -> void {
                                              destinationFile->write(reply->readAll());
                                          });
                                          QObject::connect(reply, &QNetworkReply::finished(), [&dllsToDownLoad, reply, &waitLoop]() -> void {
                                              reply->deleteLater();
                                              destinationFile->deleteLater();
                                              if (--dllsToDownLoad == 0){
                                                  manager->deleteLater();
                                                  waitLoop.quit();
                                              }
                                          });
                                      }
                                      waitLoop.exec();
                                      }
                                      

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      1 Reply Last reply
                                      4

                                      • Login

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