I have a QT application. It has functioning QPushButtons that are connected to slots in my program. I am now trying to add a new button myNewButton
, but somewhere, somehow it is not being registered.
For an existing, working button myExistingButton
I have the line:
connect(ui->myExistingButton, SIGNAL(clicked()), this, SLOT(Foo()));
I cannot simply add the line:
connect(ui->myNewButton, SIGNAL(clicked()), this, SLOT(Foo()));
The compilation error is:
class UI::Viewer has no member named 'myNewButton'
And QT Creator does not list the button as an autocomplete option for ui->
(i.e. I haven't simply mis-spelled the name). The records for myExistingButton
and myNewButton
are identical apart from coordinates and naming in the ui file. What could be causing this problem?
Have you set the widgets parent-property properly?
Either upon creation, or by explicitly setting it.
edit: Also note that
I see you solved your problem by deleting
ui_viewer.h
. But a cleaner way is to runqMake
(from theBuild
menu). I always do this when I get errors like yours -- sometimesQt Creator
forgets to runqMake
when it should.I assume you did add a new button to the .ui form and named it
myNewButton
, right? If so, this could be a synchronization issue in Qt Creator. Have you tried saving all and rebuilding (just to make sure the ui compiler is triggered) your app?I fixed this by deleting the generated file
ui_viewer.h
and then rebuilding.