qt - my qvector size is 5 but I get 10 output -


in first loop when wrote z.size()

qt has caught exception thrown event handler. throwing exceptions event handler not supported in qt. must reimplement qapplication::notify() , catch exceptions there.

and in second when wrote z.size 10 output size of z 5 can see. wrong .first 5 output 0 , rest normal 0 1 2 3 4 should have 5 output wrong

qvector<int> z(5); for(int i=0;i<5;i++)     z.push_back(i); qstring str; (int = 0; < z.size(); ++i) {     if (i > 0)         str += " ";     str += qstring::number(z[i]); } ui->mbox->settext(str);  }   

when create qvector z, give initial size of 5. means vector contains 5 zeroes. add 5 more ints, 0 4. fix change

qvector<int> z(5); 

to

qvector<int> z; 

most often, qvector not best container use, qlist better. qt's documentation:

for purposes, qlist right class use. index-based api more convenient qlinkedlist's iterator-based api, , faster qvector because of way stores items in memory. expands less code in executable.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -