Question

I am trying to compile my first Qt project in VS 2012. I am using Qt 4.8.5 opensource. I have managed to get everything compiled and I have installed the VS2012 QT add-ins. There is apparently no add-in for QT4 only QT5.

I had a very basic app compiled and running, now I'm trying to build an app using a QTableView. I'm building my database class based on the ModelView tutorial here. I am now getting the following error: CBDatabase.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall CBDatabase::data(class QModelIndex const &,int)const " (?data@CBDatabase@@UBE?AVQVariant@@ABVQModelIndex@@H@Z)

I had to change the linker properties to link against the QT4 libraries as the QT5 VS2012 add-in was attempting to link the QT5 libraries.

So my best guess is that I'm not linking the proper libraries, but I can't seem to figure out which one I'm missing.

Here is my library list: qtmaind.lib QtCored4.lib QtGuid4.lib QtSqld4.lib

Was it helpful?

Solution

The linker is telling you that you didn't define the virtual QVariant CBDatabase::data(QModelIndex const &,int) const member of your CBDatabase class. The missing member does not come from Qt, it's part of your own code. The issue has nothing to do with Qt. To reproduce it, the following suffices (that's the whole thing, doesn't need linking with Qt):

class QModelIndex {};
class QVariant {};
class CBDatabase {
public:
  // declaration, no definition
  virtual QVariant data(const QModelIndex &, int) const;
};

int main() {
  CBDatabase db;
  db.data(QModelIndex(), 0);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top