PDA

View Full Version : Adequate treatment of signal from widget (float, float, float)



nomiz
18th May 2011, 11:55
Dear all,

For my first program, I am using the amazing MathGL library to paint graphs and trajectories. The incorporated QMathGL class is extended from QWidget, and I have added this to my MainWindow.

It sends a signal void mouseClick(float,float,float). I am now capturing this signal from the QMathGL ui->qmgl with QWidget ui->vehicles_tab using

connect(ui->qmgl, SIGNAL(mouseClick(float, float, float)), ui->vehicles_tab, SLOT(on_graph_clicked(float, float, float)));
But within the class definition of ui->vehicles_tab i have defined slot on_graph_clicked as

void VehiclesTab::on_graph_clicked(float x,float y,float z)
in order to handle the value of the floats (x, y and z).

This seems to work, but i still get the warning:
QMetaObject::connectSlotsByName: No matching signal for on_graph_clicked(float,float,float)

What am I doing wrong?

Thank you in advance!

DanH
18th May 2011, 12:33
Actually, if you're getting that message it's not working -- the connect() isn't happening. ALWAYS test (eq, with an assert) the result of a connect to make sure it succeeds.

Are you sure your slot is declared as a slot?

nomiz
18th May 2011, 15:14
Commenting the connect statement prevents the click event from occurring. Enabling it again, restores the desired behavior. So it seems to work properly, but comes with the mentioned warning. In the meantime, i'll try to seek out what an assert is, en how to use it.

Commenting the connect statement prevents the click event from occurring. Enabling it again, restores the desired behavior. So it seems to work properly, but comes with the mentioned warning. In the meantime, i'll try to seek out what an assert is, en how to use it.

Added after 49 minutes:

Ah got it: I named my slot on_graph_clicked(), but on_ is reserved for slots with special meaning. Nice to know though. ;)

DanH
18th May 2011, 17:52
Yeah, that's something I'd probably read about and forgotten. Though I wouldn't expect the message unless you're doing a QMetaObject::connectSlotsByName call somewhere.

Assert, for connect is like this:

bool success = connect(...);
Q_UNUSED(success); // Prevents an "unused warning" if compiled in production mode
Q_ASSERT(success); // Will throw an assertion error if "success" is false. Compiles away in production mode.

wysota
18th May 2011, 17:59
connectSlotsByName() is called at the end of setupUi() so if one is using ui classes, the routine gets called.