View Full Version : QtListView::connect
John-P
26th January 2010, 09:49
Hi
I'm trying using QListView to filebrowsing.
QDirModel *model = new QDirModel;
list = new QListView(centralwidget); //QListView *list;
list->setGeometry(QRect(250 , 250 , 250 , 250));
list->setModel(model);
list->setRootIndex(model->index(QDir::homePath()));
QListView::connect(list , SIGNAL(pressed(QModelIndex)) , list , SLOT(setRootIndex(QModelIndex)));
I'm trying to make a function to turn back previous directory.
Does anyone have a hint or solution ?
high_flyer
26th January 2010, 11:05
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?
numbat
26th January 2010, 11:33
I found this code on my machine:
// In constructor...
root = dirModel->index(QDir::currentPath());
listView->setRootIndex(root);
// later...
void MainWindow::up_button_clicked()
{
root = root.parent();
listView->setRootIndex(root);
}
void MainWindow::listview_double_clicked(QModelIndex index)
{
if (static_cast<const QDirModel *>(index.model())->isDir(index))
{
root = index;
listView->setRootIndex(root);
}
else
{
// do something with clicked file.
vishwajeet.dusane
26th January 2010, 11:50
Hi
try this
bool QDir::cdUp ()
John-P
26th January 2010, 12:36
Thanks for reply to this thread.
I tried following code
QDirModel *model = new QDirModel;list = new QListView(centralwidget); //QListView *list;
list->setGeometry(QRect(250 , 250 , 250 , 250));
list->setModel(model);
list->setRootIndex(model->index(QDir::homePath()));
QListView::connect(list , SIGNAL(pressed(QModelIndex)) , list , SLOT(setRootIndex(QModelIndex)));
QListView::connect(list , SIGNAL(entered(QmodelIndex)) , list , SLOT(setRootIndex(QDir::cdUp())));
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
high_flyer
26th January 2010, 12:48
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.
John-P
28th January 2010, 01:28
I write following slot
void MainWindow::up_button(QModelIndex *index , QListView *view) {
view->setRootIndex(index->parent());
}
And I wrote in this slot to following code
QDirModel *model = new QDirModel;
list = new QListView(centralwidget);
//QListView *list;
list->setGeometry(QRect(250 , 250 , 250 , 250));
list->setModel(model);
list->setRootIndex(model->index(QDir::homePath()));
QListView::connect(list , SIGNAL(clicked(QModelIndex)) , list , SLOT(setRootIndex(QModelIndex)));
connect(list , SIGNAL(entered(QModelIndex)) , list , SLOT(up_button(QModelIndex , list )));
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 ?
high_flyer
28th January 2010, 08:37
where page i have to see to understand signal and slot ?
http://doc.trolltech.com/4.6/signalsandslots.html
John-P
28th January 2010, 12:03
I write two slot and "double_click" work but up_button doesn't work.
connect(list , SIGNAL(doubelClicked(QModelIndex)) , this , SLOT(doubel_click(QModelIndex)));
connect(list , SIGNAL(clicked(QModelIndex)) , this , SLOT(up_button(QModelIndex)));
void MainWindow::up_button(QModelIndex index) {
list->setRootIndex(index.parent());
}
void MainWindow::double_click(QModelIndex index) {
if(static_cast<const QDirModel *>(index.model())->isDir(index)) {
list->setRootIndex(index);
}
}
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 .
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.