PDA

View Full Version : QTableView doubleclicked event not working


sgmurphy19
24th August 2007, 15:44
I am developing this using QT4.3.1 and on a Mac OS X with intel processor.

Let me preface by saying I have read the posts:
http://www.qtcentre.org/forum/faq.php?faq=qt_signalslot
as well as
http://www.qtcentre.org/forum/f-qt-programming-2/t-qt-table-model-5276.html
and that i get no compiling errors. I have also changed the doubleclicked(QModelIndex) to doubleclicked(QModelIndex&) and doubleclicked(QModelIndex &) and still no luck.

My end objective is to have a user double click any row or cell within a QTableView and have some action as a result. But right now it appears that the double-click event is not working.

I have a QTableView which is working because I can set it's model and display data.

Right now all I expect to see is a message window, but I get nothing.

Here is my code:

void Gui::showAtriumForm()
{
atriumForm = new QMainWindow;
AtriumForm = new Ui_AtriumForm;
AtriumForm->setupUi(atriumForm);
atriumForm->show();

connect(AtriumForm->collectionsView, SIGNAL(doubleclicked(QModelIndex)), this, SLOT(rowDoubleClicked(QModelIndex)));
}


void Gui::rowDoubleClicked(QModelIndex indx)
{
QMessageBox::information(NULL, "here", "Row was double clicked");
}

The model type sholdn't matter, correct? Here is where I set it.
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT * FROM collection AS co LEFT JOIN collectors AS c ON co.Collector_ID=c.Collector_ID");
gui->AtriumForm->collectionsView->setModel(model);


All help is appreciated!
Sean

jacek
24th August 2007, 15:48
AtriumForm->setupUi(atriumForm);
Do you use two variables here or just one?

SIGNAL(doubleclicked(QModelIndex))
There is no such signal. It should be doubleClicked.

jpn
24th August 2007, 15:49
It's doubleClicked with an uppercase C. ;)

sgmurphy19
24th August 2007, 16:07
Thanks to you both! A couple hours of frustration came down to syntax! :) Any idea why no error occurred at compile?

jacek
24th August 2007, 17:31
Any idea why no error occurred at compile?
Because SIGNAL is defined this way:
#define SIGNAL(a) "2"#a
In other words, you pass strings to connect, not methods, so compiler can't check them. Although such errors can be detected at runtime, if you compile your application in debug mode and look at the console.