QVector<QPair<bool, QString> >



  • as title I have initialze these vector:

    QVector<QPair<bool, QString> >  my2dVector(10);
    

    then in myvoid with some condition I insert data in these manner:

    
    
    /****some other stupid code that change my2dVector[0] value ****/
    my2dVector[0].first = true;
    my2dVector[0].second = "blaBla";
    
    /****some other stupid code that change my2dVector[1] value ****/
    
    my2dVector[1].first = true;
    my2dVector[1].second = "etcetc";
    
    /****some other stupid code****/
    
    if(myboolvar){
    my2dVector[2].first =false;
    my2dVector[2].second = "myname";
    }
    else{
    my2dVector[2].first =true;
    my2dVector[2].second = "mysurname";
    }
    
    /****some other stupid code****/
    myintvar = 0;
    for(int i=0; my2dVector.size() > i: i++){
    if((i==2) && (my2dVector[2].second  != mycontrolQString_old)){
    myintvar = i;
    }
    }
    
    /****some other stupid code****/
    
    emit mysignal(my2dVector[myintvar].second);
    
    }
    
    /****some other stupid code****/```
    
    
    these Void run every 100ms in a QThread .... I expect that the signal always sends the last value of my2dVector[myintvar].second but instead always transmits the previous value ... what is wrong?
    
    regards
    giorgio

  • Lifetime Qt Champion

    Hi,

    Do you mean it sends the value of my2dvector.size() - 2 ?



  • So your code above looks something like this.

    // a function containing "myboolvar" definition or param?
    // ... 
    	QVector<QPair<bool, QString> >  my2dVector(10);
    	my2dVector[0].first = true;
    	my2dVector[0].second = "blaBla";
    	
    	my2dVector[1].first = true;
    	my2dVector[1].second = "etcetc";
    	
    	if(myboolvar){
    		my2dVector[2].first =false;
    		my2dVector[2].second = "myname";
    	}
    	else{
    		my2dVector[2].first =true;
    		my2dVector[2].second = "mysurname";
    	}
    	myintvar = 0;
    	for(int i=0; my2dVector.size() > i: i++){
    		if((i==2) && (my2dVector[2].second  != mycontrolQString_old)){
    			myintvar = i;
    		}
    	}
    	emit mysignal(my2dVector[myintvar].second);
    }
    

    Are you aware the logic inside your loop results in your emit only ever being able to be:

    1. my2dVector.size() < 2
      emit mysignal(my2dVector[0].second); // "blaBla"
    2. ( my2dVector.size() 2 or greater) AND myboolvar == true
      emit mysignal(my2dVector[2].second); // "myname"
    3. ( my2dVector.size() 2 or greater) AND myboolvar == false
      emit mysignal(my2dVector[2].second); // "mysurname"


  • @6thC said in QVector<QPair<bool, QString> >:

    Are you aware the logic inside your loop results in your emit only ever being able to be:

    I control today (because I write the code as I remember not as I really write it, quite sure the code is identical but not certain) ... but you are in right ...

    myintvar = 0;
    

    is an error with not desiderable result ....

    girorgio



  • @gfxx These morning I have "re-use" my void ... so I have convert my void in a regular Q_OBJECT class .. maybe I need to transform it in a QThread or run it on QFuture, because it is a graphical dynamic object that write on screen some info during the graphical transformation ... a sort of progress bar but whit custom grphics, so during the update info the graphic mouvement is breack for 50-70ms ... and the graphic render is not so fluid.

    In any case, I have discovered, using my class in other domains, that the problem of the post derives from the fact that the signals being emitted are queued, there is not a buffer enough to contain those too fast and above all there is no Traffic light that prevents the signals from overlapping.

    In all respects the signals overlapped and therefore all messages on the display did not appear.

    I've never done this sort of thing but I think I'll have to implement a traffic light ... or make a buffer that I can handle better.

    So definitively, myintvar = 0; , was only a little part of problem.

    thanks to all for the support.
    Giorgio


Log in to reply
 

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