Search code examples
qtsignals-slots

error C2976: 'QMap' : too few template arguments in QMetaObject::invokeMethod


i tryt to invoke QMetaObject::invokeMethod from object to the caller object i have this from the object :

bool bReturnInvokeMethod = false;
bool bInvokeMethod1= QMetaObject::invokeMethod(m_pCollector,
                            "setStack",
                            Qt::BlockingQueuedConnection,
                            Q_ARG(QMap<QString,QVector<std::string > >, linksQTResultMap));

but im getting this error:

error C2976: 'QMap' : too few template arguments

why its well defined type


Solution

  • The problem is that the C++ preprocessor isn't aware of templates, and Q_ARG is a macro.

    When the preprocessor sees:

    Q_MAP(foo<bar,baz>,blop)
    

    It's interpreted as a three distinct arguments (quotes to make it more visible):

    Q_MAP( "foo<bar" , "baz>" , "blop" )
    

    and the resulting expansion doesn't make sense.

    Something that usually works to counter this is to use a typedef:

    typedef QMap<QString,QVector<std::string> > MyStringVectorMap;
    ...
    Q_MAP(MyStringVectorMap, linksQTResultMap)
    ...