PDA

View Full Version : reserve a space of a list



maider
27th November 2009, 09:44
hey,

I have created a list of qstring pointers without problems. But now, i want to make this list bigger and reseved some positions free.
To get it, i have done this one:

MENU *p1 = new MENU();
TWO *p2 = new TWO();
THREE *p3 = new THREE();
FOUR *p4 = new FOUR();
FIVE *p5 = new FIVE();
SIX *p6 = new SIX();



QList<QWidget*> list;
list.insert(0,p1);
list.insert(1,null);//free
list.insert(2,null);//free
list.insert(3,null);//free
list.insert(4,null);//free
list.insert(5,null);//free
list.insert(6,null);//free
list.insert(7,null);//free
list.insert(8,null);//free
list.insert(9,null);//free

list.insert(10,p2);
list.insert(11,null);//free
list.insert(12,null);//free
list.insert(13,null);//free
list.insert(14,null);//free
list.insert(15,null);//free
list.insert(16,null);//free
list.insert(17,null);//free
list.insert(18,null);//free
list.insert(19,null);//free

list.insert(20,p3);
list.insert(21,null);//free
list.insert(22,null);//free
list.insert(23,null);//free
list.insert(24,null);//free
list.insert(25,null);//free
list.insert(26,null);//free
list.insert(27,null);//free
list.insert(28,null);//free
list.insert(29,null);//free

list.insert(30,p4);
list.insert(31,null);//free
list.insert(32,null);//free
list.insert(33,null);//free
list.insert(34,null);//free
list.insert(35,null);//free
list.insert(35,null);//free
list.insert(37,null);//free
list.insert(38,null);//free
list.insert(39,null);//free

list.insert(40,p5);
list.insert(41,null);//free
list.insert(42,null);//free
list.insert(43,null);//free
list.insert(44,null);//free
list.insert(45,null);//free
list.insert(46,null);//free
list.insert(47,null);//free
list.insert(48,null);//free
list.insert(49,null);//free

list.insert(50,p6);
list.insert(51,null);//free
list.insert(52,null);//free
list.insert(53,null);//free
list.insert(54,null);//free
list.insert(55,null);//free
list.insert(56,null);//free
list.insert(57,null);//free
list.insert(58,null);//free
list.insert(59,null);//free

But it dooesn't work! how can i reserve a space of this list free?

thanks

nish
27th November 2009, 09:51
you dont need to reserve any space... just insert the new items anywhere...
but your code does not work because u are using "null" which i dont think is "0" .. try to insert number 0 or simply use a QWidget* free =0; and insert them.

maider
27th November 2009, 10:02
iT doesn't work!
I have triyed inserting 0 instead of Null and iT doesn't work, and i have trieyed too like this:

QWidget* free =0;


QList<QWidget*> list;
list.insert(0,p1);
list.insert(1,free);//free
list.insert(2,free);//free
list.insert(3,free);//free
list.insert(4,free);//free
list.insert(5,free);//free
list.insert(6,free);//free
list.insert(7,free);//free
list.insert(8,free);//free
list.insert(9,free);//free

list.insert(10,p2);
list.insert(11,free);//free
list.insert(12,free);//free
list.insert(13,free);//free
list.insert(14,free);//free
list.insert(15,free);//free
list.insert(16,free);//free
list.insert(17,free);//free
list.insert(18,free);//free
list.insert(19,free);//free

list.insert(20,p3);
list.insert(21,free);//free
list.insert(22,free);//free
list.insert(23,free);//free
list.insert(24,free);//free
list.insert(25,free);//free
list.insert(26,free);//free
list.insert(27,free);//free
list.insert(28,free);//free
list.insert(29,free);//free

list.insert(30,p4);
list.insert(31,free);//free
list.insert(32,free);//free
list.insert(33,free);//free
list.insert(34,free);//free
list.insert(35,free);//free
list.insert(35,free);//free
list.insert(37,free);//free
list.insert(38,free);//free
list.insert(39,free);//free

list.insert(40,p5);
list.insert(41,free);//free
list.insert(42,free);//free
list.insert(43,free);//free
list.insert(44,free);//free
list.insert(45,free);//free
list.insert(46,free);//free
list.insert(47,free);//free
list.insert(48,free);//free
list.insert(49,free);//free


list.insert(50,p6);
list.insert(51,free);//free
list.insert(52,free);//free
list.insert(53,free);//free
list.insert(54,free);//free
list.insert(55,free);//free
list.insert(56,free);//free
list.insert(57,free);//free
list.insert(58,free);//free
list.insert(59,free);//free

the application run but the list doesn't work

nish
27th November 2009, 10:10
can u tell what exactly does not work? this code compiles?

maider
27th November 2009, 10:14
it compiles,i have set (in my application) that when it runs, it must show the menu screen.
This screen has some buttons to go to two,three... sceens. So when I push in menu screen to go to another screen the aplication hide.

nish
27th November 2009, 10:21
so this is not the problem of list.. this is something where you forgot to call show or even did not connected the signal... please provide a minimal compilable code for u to help you.

NoRulez
27th November 2009, 10:25
So, maybe you could use QStackedWidget for your Porblem.
Or in your case, you can use a QVector instead:



QWidget* free =0;
QVector<QWidget*> vec(60, free);
vec[0] = p1;
vec[10] = p2;
vec[20] = p3;
vec[30] = p4;
vec[40] = p5;
vec[50] = p6;


Best Regards
NoRulez