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. QVector<QPair<bool, QString> >
Forum Updated to NodeBB v4.3 + New Features

QVector<QPair<bool, QString> >

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.2k 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    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

    bkt

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

      Hi,

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

      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
      0
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by 6thC
        #3

        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"
        gfxxG 1 Reply Last reply
        3
        • 6thC6 6thC

          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"
          gfxxG Offline
          gfxxG Offline
          gfxx
          wrote on last edited by
          #4

          @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

          bkt

          gfxxG 1 Reply Last reply
          0
          • gfxxG gfxx

            @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

            gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by
            #5

            @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

            bkt

            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