Search code examples
c++qtcastingstack-overflow

Cannot convert from 'overloaded-function' to 'QLabel *'?


So, I am trying to use the following code to pass an object to a function in Qt, then convert it to a QLabel for further processing (it's part of an animation sequence):

    void myAnimation(QObject* label)
{
    QLabel *lbl = qobject_cast<QLabel*>label;

//more code.....
}

Yet, whenever I try to compile, I get the following two errors:

error: C2440: 'initializing' : cannot convert from 'overloaded-function' to 'QLabel *' Context does not allow for disambiguation of overloaded function

and

error: C2146: syntax error : missing ';' before identifier 'label'

Why isn't my code working? Any help is appreciated. Thank you!


Solution

  • Try:

    QLabel *lbl = qobject_cast<QLabel*>(label);
    //                                 ^     ^