Cory Klein
Cory Klein

Reputation: 55690

Multiple definition of operator<< in Qt project

When compiling my project I am getting a multiple definition of operator<< error from the compiler.

inline QDataStream &operator<<(QDataStream &out, ValueCountPair const &pair)
{
    out << pair.value() << pair.count();
    return out;
}

I have checked and this specific operator is only declared and/or defined once in my entire code base. Why does it say that I have multiple definitions?

Upvotes: 3

Views: 1068

Answers (1)

Cory Klein
Cory Klein

Reputation: 55690

Try doing this:

  • Clean your project by clicking Build -> Clean Project "YourProject"
  • Rebuild

I had this same issue, and I assume that moc somehow retained multiple copies of my code somewhere, causing the error. When you clean your project and rebuild it removes all the metacode created by the qmake and moc process, thus clearing the error.

This is a bug on the part of Qt.

Upvotes: 4

Related Questions