Results 1 to 20 of 21

Thread: should i use listview ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    101
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: should i use listview ?

    i try to do that
    in my class QMainWindow
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. .......................
    7. listView = new QListView(dockWidgetContents_8);
    8. listView->setObjectName(QString::fromUtf8("listView"));
    9. listView->setGeometry(QRect(0, 0, 281, 290));
    10.  
    11. listView->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    in my class ogre widget (where i create my objects
    Qt Code:
    1. ................................................. add an object
    2. QStandardItem *item=new QStandardItem(QString ("Cube %0").arg(count));
    3.  
    4. model->setItem(count,item);
    5. QListView *listview;
    6. listview->update();
    To copy to clipboard, switch view to plain text mode 
    but it dos not work

  2. #2
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: should i use listview ?

    mmmm... you should use appendRow(item) instead of setItem
    the listview->update(); is not necessary the model should send the new info to the view into the appendRow() function
    the model pointer into the add object funtion where did you get it ?

    always use "this" as the parent pointer when you use new or you will leak

  3. #3
    Join Date
    Apr 2012
    Posts
    101
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: should i use listview ?

    Quote Originally Posted by Le_B View Post
    mmmm... you should use appendRow(item) instead of setItem
    the listview->update(); is not necessary the model should send the new info to the view into the appendRow() function
    the model pointer into the add object funtion where did you get it ?

    always use "this" as the parent pointer when you use new or you will leak
    yes i use appendRow but nothing it happend
    the model pointer into the add object funtion where did you get it ?
    what you mean ? i just make that
    Qt Code:
    1. listView->setModel(model);
    To copy to clipboard, switch view to plain text mode 
    always use "this" as the parent pointer when you use new or you will leak
    where i use it ?
    (sorry i know that my questions is a lot but i try to understand to do somthing good)

  4. #4
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: should i use listview ?

    1) the listview is created into the mainwindow class and you call listView->setModel(model); into the ogre widget class
    so i want to know where you got that pointer "listview" 'just to check that it comes from the mainwindow class and is the same)

    2) all QObject can have a parent QObject pointer pass as a constructor parameter. when the parent is destroyed it will automaticaly destroy his children.
    so when you do new QStandardItemModel(); you should do new QStandardItemModel(this); for exemple
    there is very few times when you don't want to do that

  5. #5
    Join Date
    Apr 2012
    Posts
    101
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: should i use listview ?

    so i want to know where you got that pointer "listview" 'just to check that it comes from the mainwindow class and is the same
    i did not got any pointer (i just write the same code in my repling, i read that in qt assistant exemple ) shall i define pointer ? how i do that
    so when you do new QStandardItemModel(); you should do new QStandardItemModel(this); for exemple
    ahhhh, ok i will do that

  6. #6
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: should i use listview ?

    can you put the entire function please ?

  7. #7
    Join Date
    Apr 2012
    Posts
    101
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: should i use listview ?

    ok
    that's the code of add_object
    Qt Code:
    1. void OgreWidget::add_object(const Ogre::Vector3 &pos)
    2. {
    3.  
    4. Ogre::String name1 = "entity " + Ogre::StringConverter::toString(Ogre::Root::getSingletonPtr()->getTimer()->getMicroseconds());
    5. mEntity = ogreSceneManager->createEntity(name1, Ogre::SceneManager:: PT_CUBE);
    6.  
    7. Ogre::MaterialPtr material1111 = Ogre::MaterialManager::getSingleton().create("green", "General");
    8.  
    9.  
    10. material1111->getTechnique( 0 )->getPass( 0 )->setAmbient(1, 1, 0);
    11. mEntity->setMaterial(material1111);
    12. Ogre::String name = "Node " + Ogre::StringConverter::toString(Ogre::Root::getSingletonPtr()->getTimer()->getMicroseconds()); // Provides a unique timestamp - the time since the application was started in microseconds.
    13. mNode = ogreSceneManager->getRootSceneNode()->
    14. createChildSceneNode(name, pos);
    15. mNode->attachObject(mEntity);
    16. count++;
    17.  
    18. QStandardItem *item=new QStandardItem(QString ("Cube %0").arg(count));
    19.  
    20. //model->setItem(count,item);
    21. model->appendRow(item);
    22. QListView *listview;
    23. listview->update();
    24.  
    25. ogreRenderWindow->update();
    26. this->update();
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 
    i just do that

  8. #8
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: should i use listview ?

    so "model" must be a member variable of OgreWidget
    and it must be set somewhere right ?

  9. #9
    Join Date
    Apr 2012
    Posts
    101
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: should i use listview ?

    beh
    i define model in mainwinows
    Qt Code:
    1. lass MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. listView = new QListView(dockWidgetContents_8);
    8. listView->setObjectName(QString::fromUtf8("listView"));
    9. listView->setGeometry(QRect(0, 0, 281, 290));
    10.  
    11. listView->setModel(model);
    To copy to clipboard, switch view to plain text mode 
    i think i bad understand how i use the "model" no? (i modifate qt assistant exemple )

  10. #10
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: should i use listview ?

    so you must have a crash when doing model->appendRow(item); in OgreWidget right ?
    if it s true it s just that you need that ogreWidget ask for the model pointer to Mainwindow, else how do you want OgreWidget to know what model is ?

  11. #11
    Join Date
    Apr 2012
    Posts
    101
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: should i use listview ?

    you need that ogreWidget ask for the model pointer to Mainwindow, else how do you want OgreWidget to know what model is ?
    how i do that (when i see the exemple in qt assistant it make just like that maybe because he is in the same class?)
    so how i said to ogre widget to applicate the model in mainwindows , but at first is my definition of the model in mainwinows true ?

  12. #12
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: should i use listview ?

    just create a set_model function(const QStandardItemModel *model) function in ogrewiget that will save the pointer value to a member variable
    then call it after you create the model in mainwindow (i suppose you create the ogrewidget in the same function as the model)

Similar Threads

  1. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 13:01
  2. subsection in listview
    By huluyige in forum Qt Quick
    Replies: 1
    Last Post: 25th February 2011, 10:26
  3. how do you reload a listView?
    By implor in forum Newbie
    Replies: 5
    Last Post: 16th May 2010, 22:21
  4. ListView problems
    By waitingforzion in forum Newbie
    Replies: 2
    Last Post: 26th December 2009, 00:24
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05

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
  •  
Qt is a trademark of The Qt Company.