I'm having a problem with calling a function in a different class in QT creator.
Here, in the main class mainWindow.cpp
, I call a function from studentsearcher.cpp
This is a function that happens when user presses button, and the problem is with this
void MainWindow::on_FindButton1_clicked(){
StudentSearcher searchStudent;
searchStudent.exec();
searchStudent.search_id(55); // <---- the problem
}
This produces the 2 following error messages:
1.undefined reference to StudentSearcher::search_id(int)
2.collect2: ld returned 1 exit status
Here is part of the StudentSearcher.h file:
class StudentSearcher : public QDialog
{
Q_OBJECT
public:
explicit StudentSearcher(QWidget *parent = 0);
void search_id(int idNum);
~StudentSearcher();
private slots:
private:
Ui::StudentSearcher *ui;
And here is the definition of the function in the studentSearcher.cpp
void search_id(int idNum){
int idNumber = idNum;
}
I've been trying to fix this for a long time now, I've tried some pretty dumb things like this: searchStudent.exec(search_id(55));
And figured it wouldn't work, because I think that the .exec() is the constructor part.... Sorry I'm a bit nooby with coding and QT but... I can't seem to figure out how to get this stupid thing to work. I've tried many things but to no avail...
Your search_id implementation is a free function. You need to make it a member function:
void StudentSearcher::search_id(int idNum){
int idNumber = idNum;
}