View Full Version : list view get removed in Qt creator

23rd May 2011, 16:26
hello every one i am facing a problem i have made a list view in qt but the problem is that it works well when i have few item in the list i am loading item from the list in the file.my file contain 2030 items when i run the program it appear for one sec and then disappear.and nothing appear kindly help me me what should i do.

and also if i lesson the items the list appear but upon resizing the window it get removed :(

Santosh Reddy
23rd May 2011, 17:35
post a code snipet which show how you are clearing & inserting list view items, also post the relavent code you think might have the problem. Also details like when you are updating the list, stc will help centre the problem

23rd May 2011, 17:47
this is the function in which my list loaded from the file sample.txt
void list_load(QStandardItem * root)
FILE * f;
{ root->appendRow(new QStandardItem("ash"));

QString buffer ="";

char ch = ' ';
while (ch!=EOF)
buffer = buffer+'\t';

ch = fgetc(f);
buffer = buffer+ch;


// at this place we have to do the whole checking
// call 4 functions based on 4 conditions
//************************************************** ********************************
const int size =100;
char * cip = new char[100];
char *ip1='\0';
char *ip2='\0';
ip1= strtok(cip,"\t\t ");
ip2 =strtok(NULL,"\t\t");

char fn1[size]="";
char fn2[size]="";
snprintf(fn1,size,"/home/cv/mod2an3run/output/mod3run/%s_%s.csv", ip1,ip2);
snprintf(fn2,size,"/home/cv/mod2an3run/output/mod3run/%s_%s.csv", ip2, ip1);
FILE * fs ;
FILE * fd;
fs= fopen(fn1 ,"r");
fd= fopen(fn2 ,"r");

root->appendRow(new QStandardItem(buffer));
} // file not found end

// counter++; // need to change according to condition
} //while end

}// func end

here my list load function is called
void analysis::changeEvent(QEvent *e)
QStandardItemModel *listmodel = new QStandardItemModel(this);
QStandardItem * root = listmodel->invisibleRootItem();
QTimer *reloadTimer = new QTimer(this);
connect(reloadTimer, SIGNAL(timeout()), this, SLOT(list_load()));

switch (e->type()) {
case QEvent::LanguageChange:


Actually i am loading the file name from sample.txt and checking if the file exits the i will show it on the list other vise not

kindly help me i am facing strange problem like my list dissapear after some time may be i am making a mistake in the timer event.....thanks

Santosh Reddy
23rd May 2011, 18:07
Things are note very clear, First use should be using \
...\[/Code\] (without \)encapsulation for posting code, so that is syntax highlighted.

What is [Code]list_load(), how is it different from

setModel(..) has be done only once, some place like ctor or init method, not in a reoccuring event / timer

I think you should be playing (Storing and reusing) with "listmodel" and not with "root"

Is chageEvent() triggered when new data has to loaded into the view, when is it triggered?

23rd May 2011, 18:32
sir listload is same as listview(qstandard item).

setmodel is called after whole list is loaded

when ever there is an eventchange list load will b called

thats what i am thinking.......... and i m sure i am wrong

sir this is the first program i am making in qt

kindly quide me with this event thing. i am totly stuck


Santosh Reddy
23rd May 2011, 18:55
Ok, there are bunch of problems in the code, I will list them here, try correcting them

1. If you mean list_load() and list_load(QStandardItem*) are same, then it will not work. When you use connect(...) to connect a signal to a slot, both the signal and the slot should have same signature, else the connection is not made, in your case the connection is not made, hence naver called, ok still on safe side. This will not cause you a problem now, but it also does not work at all.

2. call setModel() only once, if possible in the "analysis" class ctor, and make "listmodel" as a private member variable of "analysis" class.

3. change the "list_load", with new signature of list_load(void); also make sure it is a member function (m ke sure it is declated int slot: selction of class definition) of some QObject derived class in your I assume it is your "analysis" class, if not you should make it inherit QObject;

4. you should not be using changeEvent(...), changeEvent is called when there is graphical change in the Widget like mouse hove, click, update, resize etc, you need not udate the model in this case, all the required updates are taken care by the mdel/view frame work classes, you need to update the model when there is change in the file content, which I guess you tried to monitor using the 3 sec timer, which off course will not work are said in point 1.

If this is your first Qt program, good job, you have most of the things is place, you just need to understand how things are connected, so that they make sense.

If my reply is not very clear, I suggest you to have look at Qt Docs.

23rd May 2011, 20:14
thank u so much sir for your concern and reply. i will look at them will try to remove my problem thanks a lot

Added after 31 minutes:

sir can u please tell me where to call my list_load function in the code so when program run list start loading.like where does the control go i have no idea...thanks

Santosh Reddy
24th May 2011, 04:19
you can call list_load in the "analysis" class constructor....

24th May 2011, 08:38
sir dont know what is happening my list get removed after some time it appear blanks. what should i do even the timer function in not working.....:(

Santosh Reddy
24th May 2011, 12:04
Ok post the code, I will have a look at it. Please use CODE Tags, so that it is formated properly

24th May 2011, 15:37
sir i have figured out my problem now i have to correct it

thanks so much for your concern i will ask u again i i have any problem