0

I am trying to build a program but got an error:

application_ob.cpp: In member function 'void ApplicationWindow::OBNewLoad(QString, QString)':
application_ob.cpp:103:41: error: call of overloaded 'FormatFromExt(QString&)' is ambiguous
application_ob.cpp:103:41: note: candidates are:
/usr/include/openbabel-2.0/openbabel/obconversion.h:81:24: note: static OpenBabel::OBFormat* OpenBabel::OBConversion::FormatFromExt(const char*)
/usr/include/openbabel-2.0/openbabel/obconversion.h:84:24: note: static OpenBabel::OBFormat* OpenBabel::OBConversion::FormatFromExt(std::string)

How can I patch it so to get normal build? Please explain in simple way because I do not know C++.

MSalters
  • 173,980
  • 10
  • 155
  • 350
Anixx
  • 139
  • 1
  • 1
  • 8

1 Answers1

2

Line 103 of application_ob.cpp probably reads something like:

FormatFromExt(qs);

The immediate solution would be to change this (or its equivalent) to

FormatFromExt(qs.toStdString());

However, we do not have enough information regarding the possible contents of qs to tell if the above method will work when dealing with non-latin characters. Better alternatives are presented in this answer, but to choose between them we have to know what kind of data we are dealing with.

Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806
  • 1
    Oddly, I can't see any implicit conversion to `std::string` _or_ `char const*` from [`QString`](http://doc.qt.nokia.com/latest/qstring.html), so why would _either_ overload be a candidate? – Lightness Races in Orbit Jul 15 '11 at 09:26
  • @Tomalak Geret'kal: Absolutely no idea about that... maybe the compiler is just saying "look, there's two methods with that name I could call here, but none with the argument you 're giving me". – Jon Jul 15 '11 at 09:32
  • Nah, it explicitly says there are two candidates. Not being able to find a matching function is a different beast. – Lightness Races in Orbit Jul 15 '11 at 09:34
  • @tomalak see the documentation for macro "QT_NO_CAST_TO_ASCII" on that page. – Johannes Schaub - litb Jul 15 '11 at 11:15
  • @Johannes: Ah, thanks. Odd that the implicit conversions themselves aren't documented; only how to disable them. – Lightness Races in Orbit Jul 15 '11 at 11:17
  • @Tomalak weird that it shows the `std::string` overload though. `operator char const*` won't be able to match up with a `std::string` function parameter. – Johannes Schaub - litb Jul 15 '11 at 11:23
  • Is it possible to just specify which one of the two we want without making implicit type conversion? – Anixx Jul 15 '11 at 21:32
  • Your suggestion failed: application_ob.cpp: In member function 'void ApplicationWindow::OBNewLoad(QString, QString)': application_ob.cpp:103:42: error: 'class QString' has no member named 'toStdString' – Anixx Jul 15 '11 at 21:54
  • @Anixx: Well, [it does, unless you have stdlib compatibility disabled](http://doc.qt.nokia.com/latest/qstring.html#toStdString). But then if you did this problem wouldn't have come up in the first place. Must be a really old version of Qt? – Lightness Races in Orbit Nov 08 '12 at 22:52