F
F
Fedor2014-08-30 08:44:35
Qt
Fedor, 2014-08-30 08:44:35

What to do with an undefined reference to error when passing a parameter to a function?

There is Qt_5_3_MinGW_32bit, Windiws 7 64bit.
I'm working in a graphical QT application.
The header (mainwindow.h) declares the following:

private:
    QString image_path;
    void separateImage(char* path_to_image);

Further, when the button is clicked, I call the void separateImage(char* path_to_image);
mainwindow.cpp :
The button says the following:
QByteArray ba = image_path.toUtf8(); //image_path - путь до картинки
    char *str;
    str = ba.data();
    separateImage(str); //тут компилятор говорит на ошибку

Errors:
D:\QtProjects\LabArcheo_PartCeramicResiduesAsMosaic\mainwindow.cpp:104: error: undefined reference to `MainWindow::separateImage(char*)'
and
collect2.exe:-1: error: error: ld returned 1 exit status
This error occurs if QString is passed instead of char, respectively, by changing the separate_image function.
The separate_image part of the code looks like this:
void separateImage(char* path_to_image)
{
    Mat src;
    Mat src_gray;
    int thresh = 100;
    int max_thresh = 255;
    string path;
    path.assign(path_to_image, strlen(path_to_image));
    //string bufstr = path_to_image->toStdString();
   // qDebug("dddd %d",bufstr);
    src = cv::imread(path, 1);
    cvtColor(src, src_gray, CV_BGR2GRAY);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EXL, 2014-08-30
@krox

The separate_image part of the code looks like this:
void separateImage(char* path_to_image)
{
    ...
}

And you need:
void MainWindow::separateImage(char* path_to_image)
{
    ...
}

Because you declared separateImage() as a private method of the MainWindow class .
We carefully read the Qt documentation and the C ++ language tutorial.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question