Results 1 to 9 of 9

Thread: QtListView::connect

  1. #1
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question QtListView::connect

    Hi
    I'm trying using QListView to filebrowsing.
    Qt Code:
    1. QDirModel *model = new QDirModel;
    2. list = new QListView(centralwidget); //QListView *list;
    3. list->setGeometry(QRect(250 , 250 , 250 , 250));
    4. list->setModel(model);
    5. list->setRootIndex(model->index(QDir::homePath()));
    6. QListView::connect(list , SIGNAL(pressed(QModelIndex)) , list , SLOT(setRootIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 
    I'm trying to make a function to turn back previous directory.
    Does anyone have a hint or solution ?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtListView::connect

    I'm trying to make a function to turn back previous directory.
    your code is populating the list with the lower lever of anything you click on the list. (or, makes the clicked item as root)

    Where is a code that should do the "back" functionality?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtListView::connect

    I found this code on my machine:
    Qt Code:
    1. // In constructor...
    2. root = dirModel->index(QDir::currentPath());
    3. listView->setRootIndex(root);
    4.  
    5. // later...
    6. void MainWindow::up_button_clicked()
    7. {
    8. root = root.parent();
    9. listView->setRootIndex(root);
    10. }
    11.  
    12. void MainWindow::listview_double_clicked(QModelIndex index)
    13. {
    14. if (static_cast<const QDirModel *>(index.model())->isDir(index))
    15. {
    16. root = index;
    17. listView->setRootIndex(root);
    18. }
    19. else
    20. {
    21. // do something with clicked file.
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: QtListView::connect

    Hi

    try this

    Qt Code:
    1. bool QDir::cdUp ()
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QtListView::connect

    Thanks for reply to this thread.

    I tried following code
    Qt Code:
    1. QDirModel *model = new QDirModel;list = new QListView(centralwidget); //QListView *list;
    2. list->setGeometry(QRect(250 , 250 , 250 , 250));
    3. list->setModel(model);
    4. list->setRootIndex(model->index(QDir::homePath()));
    5. QListView::connect(list , SIGNAL(pressed(QModelIndex)) , list , SLOT(setRootIndex(QModelIndex)));
    6. QListView::connect(list , SIGNAL(entered(QmodelIndex)) , list , SLOT(setRootIndex(QDir::cdUp())));
    To copy to clipboard, switch view to plain text mode 

    and i received following application output message

    Object::connect: No such slot QListView::setRootIndex(QDir::cdUp()) in window.h:86

    I thought that I must change QlistView:: to another one.
    Does this understanding is right??

    thanks regard
    Last edited by John-P; 26th January 2010 at 13:44.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtListView::connect

    Look, your problem is that you don't understand C++, and basics of the signal slot machanism and syntax.
    When you give a slot in the connect() function, you have to specify the types the slot is taking, you however are CALLING the QDir::cdUp() method.
    In addition, cdUp() returns a bool, and your slot expects a QModeIndex.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QtListView::connect

    I write following slot
    Qt Code:
    1. void MainWindow::up_button(QModelIndex *index , QListView *view) {
    2. view->setRootIndex(index->parent());
    3. }
    To copy to clipboard, switch view to plain text mode 

    And I wrote in this slot to following code

    Qt Code:
    1. QDirModel *model = new QDirModel;
    2. list = new QListView(centralwidget);
    3. //QListView *list;
    4. list->setGeometry(QRect(250 , 250 , 250 , 250));
    5. list->setModel(model);
    6. list->setRootIndex(model->index(QDir::homePath()));
    7. QListView::connect(list , SIGNAL(clicked(QModelIndex)) , list , SLOT(setRootIndex(QModelIndex)));
    8. connect(list , SIGNAL(entered(QModelIndex)) , list , SLOT(up_button(QModelIndex , list )));
    To copy to clipboard, switch view to plain text mode 

    and i see following Application output

    Object::connect: No such slot QListView::up_button(QModelIndex , list)

    where page i have to see to understand signal and slot ?

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtListView::connect

    where page i have to see to understand signal and slot ?
    http://doc.trolltech.com/4.6/signalsandslots.html
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QtListView::connect

    I write two slot and "double_click" work but up_button doesn't work.
    Qt Code:
    1. connect(list , SIGNAL(doubelClicked(QModelIndex)) , this , SLOT(doubel_click(QModelIndex)));
    2. connect(list , SIGNAL(clicked(QModelIndex)) , this , SLOT(up_button(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::up_button(QModelIndex index) {
    2. list->setRootIndex(index.parent());
    3. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::double_click(QModelIndex index) {
    2. if(static_cast<const QDirModel *>(index.model())->isDir(index)) {
    3. list->setRootIndex(index);
    4. }
    5. }
    To copy to clipboard, switch view to plain text mode 

    I write puts("debug"); in up_button() and confirm that up_button works.
    I thought that
    list->setRootIndex(index.parent());
    is wrong way to turn back .
    I have no plan .

Similar Threads

  1. How to connect?
    By starlon in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2009, 00:24
  2. Replies: 4
    Last Post: 10th November 2006, 16:38
  3. connect
    By mickey in forum Newbie
    Replies: 15
    Last Post: 2nd August 2006, 23:42
  4. many connect
    By mickey in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2006, 13:55
  5. how connect in qt4....
    By otortos in forum Newbie
    Replies: 13
    Last Post: 10th March 2006, 15:29

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.