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

StackOverflow https://stackoverflow.com/questions/22686311

  •  22-06-2023
  •  | 
  •  

Question

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.

Was it helpful?

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.

OTHER TIPS

Try actually calling the function:

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

Notice the "()" after applicationDirPath.

According to this you are passing a pointer to the static member function applicationDirPath, and arg has several overloads that all do not accept such a poitner. It seems your compiler finds several conversions of the function pointer to the parameter types arg is overloaded for and gets confused. Did you mean this:

QString msgText = QString("The file has been saved at %1\sysconf.xml")
  .arg(QApplication::applicationDirPath());
                                 //    ^^--!!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top