Results 1 to 11 of 11

Thread: list view get removed in Qt creator

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default list view get removed in Qt creator

    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
    thanks
    Last edited by maarvi; 23rd May 2011 at 16:57.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: list view get removed in Qt creator

    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

  3. #3
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: list view get removed in Qt creator

    this is the function in which my list loaded from the file sample.txt
    void list_load(QStandardItem * root)
    {
    FILE * f;
    f=fopen("/home/cv/mod2an3run/output/mod3run/sample.txt","r");
    if(f==NULL)
    { root->appendRow(new QStandardItem("ash"));

    }
    QString buffer ="";

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

    ch = fgetc(f);
    if(ch!='\n')
    {
    buffer = buffer+ch;
    }

    if(ch=='\n')
    {

    // 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];
    strcpy(cip,buffer.toStdString().c_str());
    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");
    if((fs!=NULL)&&(fd!=NULL))
    {

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

    buffer="";
    }
    // counter++; // need to change according to condition
    } //while end
    fclose(f);

    }// 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()));
    reloadTimer->start(3000);
    list_load(root);
    ui->listView->setModel(listmodel);

    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;

    default:
    break;
    }

    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

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: list view get removed in Qt creator

    Things are note very clear, First use should be using \[Code\]...\[/Code\] (without \)encapsulation for posting code, so that is syntax highlighted.

    What is
    Qt Code:
    1. list_load()
    To copy to clipboard, switch view to plain text mode 
    , how is it different from
    Qt Code:
    1. list_load(QStandardItem*)
    To copy to clipboard, switch view to plain text mode 

    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?

  5. #5
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: list view get removed in Qt creator

    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

    thanks

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: list view get removed in Qt creator

    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.

  7. The following user says thank you to Santosh Reddy for this useful post:

    maarvi (23rd May 2011)

  8. #7
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: list view get removed in Qt creator

    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
    Last edited by maarvi; 23rd May 2011 at 20:14.

  9. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: list view get removed in Qt creator

    you can call list_load in the "analysis" class constructor....

  10. #9
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: list view get removed in Qt creator

    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.....

  11. #10
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: list view get removed in Qt creator

    Ok post the code, I will have a look at it. Please use CODE Tags, so that it is formated properly

  12. #11
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: list view get removed in Qt creator

    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

    thanks
    Last edited by maarvi; 24th May 2011 at 16:28.

Similar Threads

  1. List View with sections for alphabetialy sorted list
    By woodtluk in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2010, 11:50
  2. Replies: 8
    Last Post: 6th May 2010, 11:17
  3. list view item problem..
    By addu in forum Qt Programming
    Replies: 5
    Last Post: 29th May 2009, 11:26
  4. Problem with list View
    By yuvaraj.yadav in forum Qt Programming
    Replies: 9
    Last Post: 29th April 2009, 14:02
  5. KLed in a list view
    By villy in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2006, 13:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.