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



  • Hi, I have an error here

    QDateTime &QDateTime::operator=(const QDateTime &other)
    {
        d = other.d;//error
    

    inside a lambda function the code was:

    this->pf->setDateUpload2(du);
    

    but I have put du as member variable of my object and I have tried :

    this->pf->setDateUpload2(this->du);
    

    setDateUpload was

     void setDateUpload(const QDateTime &value);
    

    and I have tried with setDateUpload2 that is :

     void setDateUpload2(QDateTime value);
    

    du is a QdateTime
    this is a parameter of the lambda and is derived of QObject :

     connect(reponse,&QNetworkReply::finished,reponse,[this,reponse](){
    

    Has someone an idea to help me ?
    I use Qt5.6.2 and I am under windows,here with a debug version of Qt.....

    [Fixed code tags ~kshegunov]



  • there is an error on !old->ref.deref() (more inside, l93 of qshareddata.h)



  • @stephane78

    Hi,

    You can try with a generic reference lambda [&]. Sometimes, depending on the compiler's implementation, lambdas require default objects to be created which may not work in all circumstances.

    -Michael.



  • @m.sue what do you mean with generic lambda [&] ? when you pass "this" as argument of the lambda you don't pass it by reference but you can modify all the variable of "this" (with my compiler mingw-w64 and even with visual studio)



  • @stephane78

    I mean replace [this,reponse]() with [&]().

    -Michael.



  • @m.sue no ,If I do that, I have an error on reponse->readAll() but I have tried [&,reponse] and I have always the same error on my operator = of QDateTime.



  • @stephane78
    hi,
    I have a hard time understanding what exactly is the problem! Any chance you could post the whole lampda here?



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

    -Michael.



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



  • @stephane78 these are my own functions...



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


  • 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....



  • 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



  • @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.



  • @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*....



  • @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...



  • 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....



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



  • 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......).



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.