Search code examples
c++qtqstring

Call of overloaded 'arg(QString (&)())' is ambiguous when called using QApplication::applicationDirPath, why?


QString msgText = QString("The file has been saved at %1\sysconf.xml").arg(QApplication::applicationDirPath);

gives me the above error. I used .arg() before, so I wonder why it gives me this error? All my other .arg() in my code works properly.


Solution

  • THE EXPLANATION

    QApplication::applicationDirPath is a static member function, to get the value you are looking for you must treat it as such, hence; you must call the function.

    Currently you are trying to pass a function pointer to QString::arg, and since the compiler cannot find a suitable overload for such construct it raises a diagnostic.


    THE SOLUTION

    QString msgText = QString(...).arg(QApplication::applicationDirPath ());
    

    Note: See the added () after QApplication::applicationDirPath.