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

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

  •  22-06-2023
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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());
                                 //    ^^--!!
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top