Reputation: 880
I followed this Qt tutorial on signals and slots, including the part where you delete the connection you can automatically make in Qt Designer and instead type in the connect
function by hand in mainwindow.cpp. I wanted to make my own slot where moving the tutorial's QSlider
changed a QLineEdit
I added, so I did this:
QLineEdit
widget named lineEdit
to my mainwindow.ui
in Qt Designer.In the MainWindow
class definition in mainwindow.h
, I added this at the bottom of the class.
public slots:
void changeLineEdit() {
ui->lineEdit->setText("Value was changed");
}
In the MainWindow
constructor in mainwindow.cpp, I added this: (ui->horizontalSlider
was the QSlider made in the tutorial.)
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), SLOT(changeLineEdit()));
When I tried to build the project, I got 9 errors, one of them being "use of undefined type Ui::MainWindow
". What did I do wrong in this edit?
The MainWindow
class definition has a private pointer Ui::Mainwindow *ui
, so I thought the slot definition would access the ui
pointer and therefore the lineEdit
widget included there.
Upvotes: 1
Views: 837
Reputation: 10827
If you implement your slot in your header make sure you include the header for UI::MainWindow
in your header for your class as well. Normally I would implement my slots in the cpp
file instead however that is not a requirement.
Upvotes: 1