Function with Signals & Slots
-
The thing is:
connect (Image_Button,SIGNAL(clicked(bool)),this,SLOT(findimage(bool))); qDebug() <<"The image path is (in main): " << fileName;
- it doesn't matter where fileName (or m_fileName) is declared, after the connect(...) call it will not be set yet because the findimage(bool) slot was not yet called. It will be called when the user clicks on the button - and you never know when the user will click the button.
-
Thank you all. Now I understand what's wrong. After the user clicks Image_Button, I want to display the image in a grid layout in which the Image_Button is. Is there a way I can go back to the grid layout AFTER the user clicked Image_Button and insert the choosen image next to the button?
-
Hi if u use @JordanHarris smart version,
you could do something like
connect(imageButton, &QPushButton::clicked, this {
imagePath = findImage();
QPixmap pic(imagePath);
ui->SomeQLabel->setPixmap(pic);
});you must insert the "SomeQLabel" into the layout. (just a normal Qlabel)
-
Hi if u use @JordanHarris smart version,
you could do something like
connect(imageButton, &QPushButton::clicked, this {
imagePath = findImage();
QPixmap pic(imagePath);
ui->SomeQLabel->setPixmap(pic);
});you must insert the "SomeQLabel" into the layout. (just a normal Qlabel)
@mrjj ,
I implementedconnect(Image_Button, &QPushButton::clicked, [this]() { imagePath = findimage(); })
and I got the following error message:
C:\Programming\backup\Folkfriends\additem.cpp:195: error: no match for 'operator=' (operand types are 'QString' and 'void')
connect(Image_Button, &QPushButton::clicked, this { imagePath = findimage(); });
^
I'm wondering what am I missing. -
well basically it says you are doing
void = QString
so check that findimage returns Qstring and that
imagePath is also declared Qstring -
well basically it says you are doing
void = QString
so check that findimage returns Qstring and that
imagePath is also declared Qstring -
Does ur compiler support lambdas?
Try with empty { }connect(Image_Button, &QPushButton::clicked, [this]() { })
you need Qt 5.5 and newer compiler.
-
Does ur compiler support lambdas?
Try with empty { }connect(Image_Button, &QPushButton::clicked, [this]() { })
you need Qt 5.5 and newer compiler.
-
@gabor53
well it can then compile the line.
what compiler is it ?
VS or mingw?
and what version? -
@gabor53
It's not the lambda.imagePath = findimage(QString);
This doesn't make sense neither to the compiler nor to me, so you should fix it. What argument are you trying to use
findimage
with? Currently it has none, and instead of an argument a type name is provided.Kind regards.
-
@gabor53
It's not the lambda.imagePath = findimage(QString);
This doesn't make sense neither to the compiler nor to me, so you should fix it. What argument are you trying to use
findimage
with? Currently it has none, and instead of an argument a type name is provided.Kind regards.
@kshegunov
ahh good spotted. thats the void = QString :)
I completely missed that .) -
@kshegunov
ahh good spotted. thats the void = QString :)
I completely missed that .) -
@mrjj
I just read the compiler errors, it says it right there:expected primary-expression before ')' token
;)
@kshegunov
yeah it's a meaningful and good compiler error :) -
Heheh, of course that's right. I gotta get back to programming again, I been installing , upgrading and reading too much...
** it doesn't matter where fileName (or m_fileName) is declared, after the connect(...) call it will not be set yet because the findimage(bool) slot was not yet called. It will be called when the user clicks on the button - and you never know when the user will click the button. ** -
I changed the following line:
connect(Image_Button, &QPushButton::clicked, [this]() { imagePath = findimage( QString);}); to
connect(Image_Button, &QPushButton::clicked, [this]() { imagePath = findimage( fileName);});
Now I get the following error message: C:\Programming\backup\Folkfriends\additem.cpp:195: error: no match for 'operator=' (operand types are 'QString' and 'void') connect(Image_Button, &QPushButton::clicked, [this]() { imagePath = findimage( fileName);}); What else to change? Thank you.
-
Hi
in the first post you show it as
findimage(bool)so that would be callable as
imagePath = findimage( true);So what you give it as parameter, depends on how u declare it.
(in the .h file) -
Hi
in the first post you show it as
findimage(bool)so that would be callable as
imagePath = findimage( true);So what you give it as parameter, depends on how u declare it.
(in the .h file)