views:

301

answers:

3

Hi,

I have installed Qt and Qt for VS plugin. Everything works fine, UI applications compile and run that's ok, but connecting signals and slots doesn't. I have Q_OBJECT in my class and for connecting I am using this code in constructor:

connect(ui.mainTableView, SIGNAL(activated(const QModelIndex &)),
        this, SLOT(showDetail(const QModelIndex &)));

EDIT:

showDetail method:

void MyClass::showDetail(const QModelIndex &index)
{
    this->setWindowTitle("it works");
}

window title is not changed and breakpoint is not reached.

moc files are generated in Generated Files directory, but moc file of that class is empty (others not), I think that it is because the class has no signal, but only one slot.

even connections generated by Designer don't work and the call of connect method returns true.

+2  A: 

Have you got the moc working correctly? That would explain why the connect isn't doing its thing, but everything else is...

Skilldrick
moc files are generated in `Generated Files` directory, but moc file of that class is empty (others not), I think that it is because the class has no signal, but only one slot.
Steve
moc_MyClass.cpp should not be empty even if you your class is empty, did you inherit `MyClass` from `QObject`?
Paul
Yes it inherits from QMainWindow. (It's really strange.)
Steve
Without `moc`-generated code, signals and slots won't work. Try to find out why `moc` generates empty file. Does `moc` display any warnings when processing your `MyClass.h`?
Paul
Have you tried copying all the code into a new project? I remember when I used to use Qt, I had lots of problems with QMake and the like, and sometimes it seemed like it just skipped over stuff.
Skilldrick
+3  A: 

Remove variable names from SIGNAL and SLOT macros:

connect(ui.mainTableView, SIGNAL(activated(const QModelIndex &)),
    this, SLOT(showDetail(const QModelIndex &)));

For more details, read documentation on QObject::connect carefully.

Paul
This looks like the correct answer to me.
Skilldrick
Unfortunately it doesn't work for me :-(
Steve
Did you mark your `MyClass::showDetail` as slot in `MyClass` class definition?
Paul
Yes using `public slots: void showDetail(const QModelIndex `.
Steve
A: 

RESULT:

Oh no it turns out to be a silly question, thanks everybody, all answers pushed me towards the solution, but the last step was to find out that on my platform items are activated only by double-click, not single. Sorry

Steve