I have a QDialog that I am using to select from a list of items displayed from an SQL table. Once an item is selected I need to go back to the table and read all the data for the selected item. I want to add the SQL ID to the WidgetItem.
I have created a class that inherits from QListWidgetItem. All I want to do is add an integer ID. I am getting all sorts of compile errors related to Meta Objects.
Here is the header:
#ifndef MYLISTWIDGETITEM_H
#define MYLISTWIDGETITEM_H
#include <QListWidget>
#include <QListWidgetItem>
class MyListWidgetItem : public QListWidgetItem
{
Q_OBJECT
public:
explicit MyListWidgetItem(QListWidget *parent = 0);
explicit MyListWidgetItem(QString content, QListWidget *parent = 0);
~MyListWidgetItem();
int getSqlTblEntryKey() const;
void setSqlTblEntryKey(int);
private:
int sqlTblEntryKey;
};
#endif // MYLISTWIDGETITEM_H
And this is the source"
#include "mylistwidgetitem.h"
MyListWidgetItem::MyListWidgetItem(QListWidget *parent) :
QListWidgetItem(parent)
{
}
MyListWidgetItem::MyListWidgetItem(QString content, QListWidget *parent) :
QListWidgetItem(content, parent)
{
}
MyListWidgetItem::~MyListWidgetItem()
{
}
int MyListWidgetItem::getSqlTblEntryKey() const
{
return sqlTblEntryKey;
}
void MyListWidgetItem::setSqlTblEntryKey(int value)
{
sqlTblEntryKey = value;
}
I'm getting these errors:
10:43:35: Running steps for project LEAPv1.7.1...
10:43:35: Configuration unchanged, skipping qmake step.
10:43:35: Starting: "C:\Qt\Qt5.3.1\Tools\QtCreator\bin\jom.exe"
C:\Qt\Qt5.3.1\Tools\QtCreator\bin\jom.exe -f Makefile.Debug cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\LEAPV1.7.1.pdb -DUNICODE -DWIN32 -DQT_YES_DEBUG_OUTPUT -DQT_MULTIMEDIAWIDGETS_LIB -DQT_OPENGL_LIB -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I"....\SFML-2.1\include" -I"....\Progra~2\Carmenta\Carmen~1\include" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtMultimediaWidgets" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtOpenGL" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtMultimedia" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtWidgets" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtSerialPort" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtSql" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtNetwork" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtGui" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore" -I"debug" -I"." -I"." -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\GLENNP~1\AppData\Local\Temp\mylistwidgetitem.obj.1304.109.jom
mylistwidgetitem.cpp
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\bin\moc.exe -DUNICODE -DWIN32 -DQT_YES_DEBUG_OUTPUT -DQT_MULTIMEDIAWIDGETS_LIB -DQT_OPENGL_LIB -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1600 -D_WIN32 -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/mkspecs/win32-msvc2010 -IC:/Qt-Projects/LEAP/LEAPv1.7.1 -IC:/SFML-2.1/include -IC:/Progra~2/Carmenta/Carmen~1/include -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtMultimediaWidgets -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtOpenGL -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtMultimedia -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtWidgets -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtSerialPort -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtSql -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtNetwork -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtGui -IC:/Qt/Qt5.3.1/5.3/msvc2010_opengl/include/QtCore -I. ....\Qt-Projects\LEAP\LEAPv1.7.1\mylistwidgetitem.h -o debug\moc_mylistwidgetitem.cpp cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\LEAPV1.7.1.pdb -DUNICODE -DWIN32 -DQT_YES_DEBUG_OUTPUT -DQT_MULTIMEDIAWIDGETS_LIB -DQT_OPENGL_LIB -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I"....\SFML-2.1\include" -I"....\Progra~2\Carmenta\Carmen~1\include" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtMultimediaWidgets" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtOpenGL" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtMultimedia" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtWidgets" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtSerialPort" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtSql" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtNetwork" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtGui" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore" -I"debug" -I"." -I"." -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\GLENNP~1\AppData\Local\Temp\addressdialog.obj.1304.125.jom
addressdialog.cpp
cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\LEAPV1.7.1.pdb -DUNICODE -DWIN32 -DQT_YES_DEBUG_OUTPUT -DQT_MULTIMEDIAWIDGETS_LIB -DQT_OPENGL_LIB -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I"....\SFML-2.1\include" -I"....\Progra~2\Carmenta\Carmen~1\include" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtMultimediaWidgets" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtOpenGL" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtMultimedia" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtWidgets" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtSerialPort" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtSql" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtNetwork" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtGui" -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore" -I"debug" -I"." -I"." -I"....\Qt\Qt5.3.1\5.3\msvc2010_opengl\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\GLENNP~1\AppData\Local\Temp\moc_mylistwidgetitem.obj.1304.390.jom
moc_mylistwidgetitem.cpp
debug\moc_mylistwidgetitem.cpp(63) : error C2039: 'staticMetaObject' : is not a member of 'QListWidgetItem'
c:\qt\qt5.3.1\5.3\msvc2010_opengl\include\qtwidgets\qlistwidget.h(61): see declaration of 'QListWidgetItem' jom: C:\Qt-Testing\LEAPv1.7.1\Makefile.Debug [debug\moc_mylistwidgetitem.obj] Error 2
debug\moc_mylistwidgetitem.cpp(70) : error C2227: left of '->metaObject' must point to class/struct/union/generic type
debug\moc_mylistwidgetitem.cpp(70) : error C2227: left of '->dynamicMetaObject' must point to class/struct/union/generic type
debug\moc_mylistwidgetitem.cpp(78) : error C2039: 'qt_metacast' : is not a member of 'QListWidgetItem'
c:\qt\qt5.3.1\5.3\msvc2010_opengl\include\qtwidgets\qlistwidget.h(61): see declaration of 'QListWidgetItem' debug\moc_mylistwidgetitem.cpp(83) : error C2039: 'qt_metacall' : is not a member of 'QListWidgetItem'
c:\qt\qt5.3.1\5.3\msvc2010_opengl\include\qtwidgets\qlistwidget.h(61): see declaration of 'QListWidgetItem' jom: C:\Qt-Testing\LEAPv1.7.1\Makefile [debug] Error 2
10:43:38: The process "C:\Qt\Qt5.3.1\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project LEAPv1.7.1 (kit: Desktop Qt 5.3 MSVC2010 OpenGL 32bit) When executing step 'Make'
10:43:38: Elapsed time: 00:03.
I don't have a clue what to do. I just wanted to add an integer to the class so I don't have to maintain another table internally. Obviously I don't understand what I am doing here!