Qt Creator, call a function

Go To StackoverFlow.com

1

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...

2012-04-05 18:01
by Gabriel


4

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;
}
2012-04-05 18:06
by NoName
Hey when I replaced the function with what you put, it had a problem with the header file. It kept saying this: extra qualification 'StudentSearcher::' on member 'search_id - Gabriel 2012-04-05 18:17
Fixed it, in the header and top of the cpp file the function had to be declared as I had it earlier, but in the definition it was declared the way you suggested - Gabriel 2012-04-05 18:27
Ads