tags:

views:

1018

answers:

1

I am working on a simple drawing widget in Qt (all of the following is within one class). In the header file, I have defined

private:
QPointF translateToCanvas (QPointF input);

and in the CPP file I have defined

QPointF translateToCanvas (QPointF input) {
    return input - QPointF(CANVAS_MARGIN_X, CANVAS_MARGIN_Y);
}

Somewhere else in the code, I call this with

QPointF newPoint = translateToCanvas(anotherPoint);

Whenever I compile, it gives me the error "undefined reference to `MyClass::translateToCanvas(QPointF)'", and this is happening inside the stuff that moc's generating and not actually my literal code.

What could be causing this error in Qt? (I'm using Qt Creator with Qt 4.5.)

+4  A: 

This has nothing to do with Qt.

QPointF translateToCanvas (QPointF input) {
    return input - QPointF(CANVAS_MARGIN_X, CANVAS_MARGIN_Y);
}

defines a standalone function named translateToCanvas, which has nothing to do with the private method you declared in your class, other than happening to have the same name. You want

QPointF MyClass::translateToCanvas (QPointF input) {
     return input - QPointF(CANVAS_MARGIN_X, CANVAS_MARGIN_Y);
}
Logan Capaldo