QStringList is interpreted as an alias of QList<QString> in some contexts

82 Views Asked by At

I've noticed that in two different build contexts, QStringList can be eihter interpreted as its own class, or as an alias to QList<QString>. The former is the expected behavior according to the documentation, while the latter is beyond my understanding.

I've developed a library that defines the following method:

void findObject(const QString& objectType, int id, const QStringList& fields, std::function<void(QVariant)> callback);

(See: https://github.com/planed-es/QtOdoo/blob/da3419a721b1088223c472c82df9c325aafb1061/QOdoo.h#L137)

The library builds as expected, but when trying to create an executable that links to any of the functions or methods that use QStringList in its definition, I am being told that I'm using an undefined reference to:

OdooService::findObject(QString const&, int, QList<QString> const&, std::function<void (QVariant)>)

Looking at the definition, it is not identical as the header's, which defines it as following:

OdooService::findObject(QString const&, int, QStringList const&, std::function<void (QVariant)>)

I modified the library to replace all occurences of QStringList with QList<QString>, to try and remove the ambiguity. When I remove references to QStringList in any declarations that will be shared with other build targets, it builds and works as intented. I suppose this means that QStringList is interpreted in two different ways, depending on whether I'm building the library or my executable.

I've been able to reproduce the issue with a minimal example:

#include <QOdoo.h>

int main(int argc, char *argv[])
{
  OdooService service(QUrl("http://hello.com"));

  service.findObject("res.partner", 2, QStringList{}, [](QVariant) {});
  return 0;
}

This example fails to build if findObject is defined using QStringList. However, it builds properly if I rewrite its definition using QList<QString> instead. I'm pretty sure this is not supposed to happen. Anyone knows what might be up ?

0

There are 0 best solutions below