Qt in visual studio: connecting slots and signals doesn't work
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 conne开发者_如何转开发cting 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
.
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.
Have you got the moc
working correctly? That would explain why the connect
isn't doing its thing, but everything else is...
In Visual Studio 2012, when trying to use
connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));
I get errors for plot
and SIGNAL
.
This is because the incorrect connect was found by Visual Studio. It found the connect
in winsock.h
.
To fix the errors, I used the QObject
namespace as follows:
QObject::connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));
For reference, here is info on the errors.
For the first plot
argument the error is:
ERROR: argument of type "QCPAxis*" is incompatible with parameter of type "Socket".
For the first SIGNAL
the error is:
ERROR: argument of type "cosnt Char*" is incompatible with parameter of type "const sockaddr*".
For the second plot
argument the error is:
ERROR: argument of type "QCPAxis*" is incompatible with parameter of type "int".
For the second SIGNAL
the error is:
ERROR: too many arguments in function call.
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
精彩评论