Solved QObject::connect: Cannot connect (null)::clicked() to ScanFrame::OnBtnStartScanClicked()
-
Hello All,
I am using qt 5.14 with msvc 2019 compiler.
I created a form file class in the visual studio then add a button to the form and when I am trying to call slot I am getting the following messageFor reference:
connect(_ui->btnStart, SIGNAL(clicked()), this, SLOT(OnBtnStartScanClicked())); -
@Kira As the error message says the sender (_ui->btnStart) is null.
Is your UI initialised when you're trying to connect?
Also, connect() does not call the slot, it only connects a signal to a slot. -
@jsulm : Yes, Ui is connected
Given below ins the lines from the constructor function
_ui = new Ui::Frame();
connect(_ui->btnStart, SIGNAL(clicked()), this, SLOT(OnBtnStartScanClicked())); -
@Kira
what exactly is the error/warning message and is there a difference, when you change it to Qt5-Syntax? -
@Kira said in QObject::connect: Cannot connect (null)::clicked() to ScanFrame::OnBtnStartScanClicked():
btnStart
Is this really initialised?
-
@jsulm : Its part of qtdesigner.
-
@J-Hilk : Ok thanks will try it
-
Hi,
Don't forget to call setupUi from the ui object otherwise you are not going to get what you expect.
-
@SGaist : Its being called _ui->setupUi(this);
-
@jsulm: Also I am trying to display image on QLabel its not being displayed.
I checked the slot is being called but the image is not being displayed.
Please refer to the below slot code.QPixmap pix; pix.load("cat.jpg"); pix.scaled(_ui->lblROICamera->size(), Qt::KeepAspectRatio); _ui->lblCamera->setPixmap(QPixmap::fromImage(img));
-
Because the path to that picture is relative so unless you have that file in the same folder as the executable, it won't be loaded.
-
@SGaist :its present. I verified, actually, I haved worked with images multiple times, don't know y its showing strange behavior;
-
@Kira said in QObject::connect: Cannot connect (null)::clicked() to ScanFrame::OnBtnStartScanClicked():
its present
executable, not project file!
-
@J-Hilk :ohh.
Executable is being generated but its not in the debug folder. I have provided a separated folder for the exe file -
@Kira Is the image in the SAME directory as the executable?
-
@jsulm : One more thing I am using a promoted widget which is QFrame consisting of QLabel and QPushbutton.
When I put label in the base class the image gets displayed but when I write the same code in the promoted widget it is not being displayed.Base Widget label:
After pasting the similar code in promoted widget:
-
@Kira Without code I have no idea...
-
@jsulm : Every connect statement I get a warning : avoid unnamed object with custom constructor and destructor.
Also, I also figured the problem is in the slot of the promoted widget. When I try to write the code to display the image in constructor it works fine but when I add the same code in the slot it failed to display the image.
I have also checked that the slot is invoked every time by placing a breakpoint in the respective slot. -
@Kira Sorry, without code and exact error messages others can only guess...
-
@jsulm : Thanks for highlighting the issue.
As mentioned earlier, I had created a base widget and promoted widget.
In the designer, I promoted the widget, and in the class file of the base widget, I created an object of the promoted widget to pass some initialization parameter. There I called the signal to slot connection.I finally figured that the connections start working after I added them after
_ui->setupUi(this); or called them in showEvent().
Since _ui->setupUi(this); is declared in the constructor of the promoted widget. I never thought this could be the issue.
I finally got the example working by adding them in the showEvent()