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. error on operator= of QDateTime in a lambda, Qt5.6.2
Qt 6.11 is out! See what's new in the release blog

error on operator= of QDateTime in a lambda, Qt5.6.2

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 3 Posters 9.2k 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.
  • m.sueM m.sue

    ...and setDateUpload(2). I cannot find it as Qt function.

    -Michael.

    S Offline
    S Offline
    stephane78
    wrote on last edited by
    #9

    @m.sue ```
    void MyFichier::setDateUpload(const QDateTime &value)
    {
    dateUpload = value;
    }
    void MyFichier::setDateUpload2(QDateTime value)
    {
    dateUpload = value;
    }

    S 1 Reply Last reply
    0
    • S stephane78

      @m.sue ```
      void MyFichier::setDateUpload(const QDateTime &value)
      {
      dateUpload = value;
      }
      void MyFichier::setDateUpload2(QDateTime value)
      {
      dateUpload = value;
      }

      S Offline
      S Offline
      stephane78
      wrote on last edited by stephane78
      #10

      @stephane78 these are my own functions...

      S 1 Reply Last reply
      0
      • S stephane78

        @stephane78 these are my own functions...

        S Offline
        S Offline
        stephane78
        wrote on last edited by stephane78
        #11

        here is the lambda

        
        connect(reponse,&QNetworkReply::finished,reponse,[this,reponse](){
                
               
        
              
        
        
           QString strReply = QString::fromUtf8(reponse->readAll());
            QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
            QJsonObject jsonObject = jsonResponse.object();
        
        
            long idFichier = (long)jsonObject["fileId"].toDouble();
           
              QDateTime du = QDateTime::fromString(jsonObject["dateUpload"].toString(),"yyyy-MM-dd HH:mm:ss");
        
            QDateTime dup;
            if(this->flag)
                dup = QDateTime::fromString(jsonObject["updated_at"].toString(),"yyyy-MM-dd HH:mm:ss");
           
          
          
            int code=jsonObject["code"].toInt();
        
        
        if(idFichier > 0)
        {
                 if(!this->flag)
                    this->pf->setId(idFichier);
                 if(this->flag)
                     this->pf->setDateUpload2(dup);
                 else this->pf->setDateUpload2(du);
                 ....
        
        S 1 Reply Last reply
        0
        • S stephane78

          here is the lambda

          
          connect(reponse,&QNetworkReply::finished,reponse,[this,reponse](){
                  
                 
          
                
          
          
             QString strReply = QString::fromUtf8(reponse->readAll());
              QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
              QJsonObject jsonObject = jsonResponse.object();
          
          
              long idFichier = (long)jsonObject["fileId"].toDouble();
             
                QDateTime du = QDateTime::fromString(jsonObject["dateUpload"].toString(),"yyyy-MM-dd HH:mm:ss");
          
              QDateTime dup;
              if(this->flag)
                  dup = QDateTime::fromString(jsonObject["updated_at"].toString(),"yyyy-MM-dd HH:mm:ss");
             
            
            
              int code=jsonObject["code"].toInt();
          
          
          if(idFichier > 0)
          {
                   if(!this->flag)
                      this->pf->setId(idFichier);
                   if(this->flag)
                       this->pf->setDateUpload2(dup);
                   else this->pf->setDateUpload2(du);
                   ....
          
          S Offline
          S Offline
          stephane78
          wrote on last edited by
          #12

          I think I could try with the release version because perhaps there isn't any error with the release version.....because here I am with the debug version and with the debugger and with a 64 bits debug version of Qt and Qtcreator....

          S m.sueM 2 Replies Last reply
          0
          • S stephane78

            I think I could try with the release version because perhaps there isn't any error with the release version.....because here I am with the debug version and with the debugger and with a 64 bits debug version of Qt and Qtcreator....

            S Offline
            S Offline
            stephane78
            wrote on last edited by
            #13

            OK this problem is solved, I have put a mutexlocker with a mutex before pf->setid and ml.unlock after setdateupload2 because this is an object associated to a secondary thread with movetothread and now I haven't any more this error. I Have another error further but I put a mutexlocker too and see

            1 Reply Last reply
            0
            • S stephane78

              I think I could try with the release version because perhaps there isn't any error with the release version.....because here I am with the debug version and with the debugger and with a 64 bits debug version of Qt and Qtcreator....

              m.sueM Offline
              m.sueM Offline
              m.sue
              wrote on last edited by m.sue
              #14

              @stephane78

              There is something fishy with your lambda I think. You do not use &, which means the setDateUpload function works on a copy -> a temporary. You probably will want to work on something like:

              QDateTime &dateUpload=pf->dateUpload;
              connect(reponse,&QNetworkReply::finished,reponse,[&dateUpload,response](){
              ...
              });

              EDIT: ok you did not tell about multithreading, either :-)

              -Michael.

              S 1 Reply Last reply
              2
              • m.sueM m.sue

                @stephane78

                There is something fishy with your lambda I think. You do not use &, which means the setDateUpload function works on a copy -> a temporary. You probably will want to work on something like:

                QDateTime &dateUpload=pf->dateUpload;
                connect(reponse,&QNetworkReply::finished,reponse,[&dateUpload,response](){
                ...
                });

                EDIT: ok you did not tell about multithreading, either :-)

                -Michael.

                S Offline
                S Offline
                stephane78
                wrote on last edited by
                #15

                @m.sue I have still the error on operator so I will now try what you said ,but I have already tried with du and dup a members variables of this and it was not good*....

                S 1 Reply Last reply
                0
                • S stephane78

                  @m.sue I have still the error on operator so I will now try what you said ,but I have already tried with du and dup a members variables of this and it was not good*....

                  S Offline
                  S Offline
                  stephane78
                  wrote on last edited by kshegunov
                  #16

                  @m-sue,Hi michael, thanks a lot,it was fast the solution : I have began to replace all the pointers on the instance of my own class with such a thing in the lambda and it seems to work : for example :

                  MyFichier * &pf2=pf;
                   connect(reponse,&QNetworkReply::finished,reponse,[this,&pf2,reponse](){
                  

                  and I haven't any problem any more with the QDateTime...

                  S 1 Reply Last reply
                  1
                  • S stephane78

                    @m-sue,Hi michael, thanks a lot,it was fast the solution : I have began to replace all the pointers on the instance of my own class with such a thing in the lambda and it seems to work : for example :

                    MyFichier * &pf2=pf;
                     connect(reponse,&QNetworkReply::finished,reponse,[this,&pf2,reponse](){
                    

                    and I haven't any problem any more with the QDateTime...

                    S Offline
                    S Offline
                    stephane78
                    wrote on last edited by
                    #17

                    I have still a problem with dateupload and shash...it seems that the other problems are solved (it seems ) but not for dateupload and shash....

                    S 1 Reply Last reply
                    0
                    • S stephane78

                      I have still a problem with dateupload and shash...it seems that the other problems are solved (it seems ) but not for dateupload and shash....

                      S Offline
                      S Offline
                      stephane78
                      wrote on last edited by
                      #18

                      still the error on !old->ref.deref()

                      S 1 Reply Last reply
                      0
                      • S stephane78

                        still the error on !old->ref.deref()

                        S Offline
                        S Offline
                        stephane78
                        wrote on last edited by stephane78
                        #19

                        OK, I am not sure that my compiler,mingw-w64 4.9.2, supports well the lambdas and I think I will try with mingw-w64 5.3.0 (but I must build a release and a debug version of Qt and my other libs with it......).

                        S 1 Reply Last reply
                        0
                        • S stephane78

                          OK, I am not sure that my compiler,mingw-w64 4.9.2, supports well the lambdas and I think I will try with mingw-w64 5.3.0 (but I must build a release and a debug version of Qt and my other libs with it......).

                          S Offline
                          S Offline
                          stephane78
                          wrote on last edited by
                          #20

                          so it not mingw 4.9.2. so is there any way to replace the loop.exec() in that code ?

                          QNetworkReply * reponse = netmanager->post(requete,multiPart);
                          
                                
                          
                               QEventLoop loop;
                                 
                                 connect(reponse, SIGNAL(finished()), &loop, SLOT(quit())) ;
                          
                                 loop.exec();
                          
                          

                          (but not a lambda because I have problems with the lambda)

                          S 1 Reply Last reply
                          0
                          • S stephane78

                            so it not mingw 4.9.2. so is there any way to replace the loop.exec() in that code ?

                            QNetworkReply * reponse = netmanager->post(requete,multiPart);
                            
                                  
                            
                                 QEventLoop loop;
                                   
                                   connect(reponse, SIGNAL(finished()), &loop, SLOT(quit())) ;
                            
                                   loop.exec();
                            
                            

                            (but not a lambda because I have problems with the lambda)

                            S Offline
                            S Offline
                            stephane78
                            wrote on last edited by stephane78
                            #21

                            I post another thread for this...this subject is closed,because I don't see any way for this lambda....

                            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