PDA

View Full Version : Help me with "connect"



skipper
20th April 2016, 14:01
QCheckBox *ledek[64];
int ledcounter=0;
for(int i=0;i<8;i++)
{
for(int l=0;l<8;l++)
{
ledek[ledcounter]=new QCheckBox(this);
ledek[ledcounter]->setGeometry(40+(20*i), 60+(20*l), 20, 20);
ledek[ledcounter]->show();
MainWindow::connect(ledek[ledcounter], SIGNAL(stateChanged(int)), this, SLOT(kuldes(ledcounter+100)));
ledcounter++;
}
}
there is a problem in the connect line, it says expected token ")" got ";", but it compiles, also it can't connect to the slot, which is a function made by me, it says this: QObject::connect: No such slot MainWindow::kuldes(ledcounter+100) in ../kettodesledmatrix/mainwindow.cpp:32
QObject::connect: (receiver name: 'MainWindow')

anda_skoa
20th April 2016, 14:28
The SIGNAL and SLOT macros take function signatures only, i.e. the function name and the list of argument types.
You have "ledcounter+100" in your SLOT macro, but "ledcounter+100" is not a valid C++ type.

Cheers,
_

skipper
20th April 2016, 14:36
the kuldes function:
void MainWindow::kuldes(int asd)
{
for(int n = 0; n != sizeof asd; ++n)
{
output.append((char)((asd & (0xFF << (n*8))) >> (n*8)));
}
qDebug() << output;
serial->write(output);
}
how should i pass the numbers?

anda_skoa
20th April 2016, 16:03
QSignalMapper.

Cheers,
_

Radek
20th April 2016, 17:06
You cannot connect stateChanged() to kuldes() this way. stateChanged() signals that the checkbox has been checked (argument = 1) or unchecked (argument = 0). So kuldes() gets only 0 or 1 from stateChanged(). If you want to pass some integer value, you need to use some variable visible in kuldes() while processing stateChanged(). One possibility is deriving your own checkbox with ledcounter as an additional data member, defining your own signal, say MyStateChanged, connecting stateChanged to yourself a whenever the state changes, update ledcounter and emit MyStateChanged(). Now, connect MyStateChanged to kuldes(). kuldes() can now get the right checkbox using sender() and see the ledcounter.

The correct connect() at line 10 should be:


MainWindow::connect(ledek[ledcounter], SIGNAL(stateChanged(int)), this, SLOT(kuldes(int)));