QObject::connect crashing
-
I have a simple class that inherits from QWidget and am using the Q_OBJECT macro in my class defnition. I am compiling the header file using moc and including the generated cpp file in my class definition cpp. In the contructor of my class I am attempting to connect a signal from a button to a slot defined in my class. During runtime I am seeing a crash in the connect call and it appears that the metadata for the generated class contains a bunch of NULLs which are the source of the crash as they are dereferenced down in the connect call.
I have used the moc compiler many times on other projects, so I must be missing something either in the command line for moc or some setup prior to the connect calls. Any ideas?
-
can you provide any source code?
Otherwise it's hard to help. -
Is the button already created at the time you are connecting to it?
-
I will post code when I get home from work, but the button should be constructed in the setupUi routine which is called before the connect.
-
Okay here is the code:
header file for moc file generation
@
#pragma once#include <QDockWidget>
namespace Ui {
class EditToolWidget;
}class EditToolImpl : public QObject
{
Q_OBJECT
public:
EditToolImpl(QDockWidget& parent);
~EditToolImpl(void);public slots:
void colorToolButtonClicked();private:
Ui::EditToolWidget *m_ui;
};
@cpp file that initializes the UI and connects the one slot
@
#include "EditToolImpl.h"
#include <QColorDialog>
#include "generated\ui_editToolDockWidget.h"EditToolImpl::EditToolImpl(QDockWidget& parent)
{
m_ui = new Ui::EditToolWidget();
m_ui->setupUi(&parent);
QObject::connect(m_ui->colorToolButton, SIGNAL(clicked()), this, SLOT(colorToolButtonClicked()));
}EditToolImpl::~EditToolImpl(void)
{
}void EditToolImpl::colorToolButtonClicked() {
QColor color;
color = QColorDialog::getColor(Qt::green, m_ui->dockWidgetContents, QString("Select Color"), QColorDialog::DontUseNativeDialog);
}
@The command to compile the header file:
$(SolutionDir)\ThirdParty\Qt\4.8.0\bin\moc.exe -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"$(SolutionDir)\ThirdParty\Qt\4.8.0\include\QtCore" -I"$(SolutionDir)\ThirdParty\Qt\4.8.0\include\QtGui" -I"$(SolutionDir)\ThirdParty\Qt\4.8.0\include" -I"$(SolutionDir)\ThirdParty\Qt\4.8.0\include\ActiveQt" -I"." -I"$(SolutionDir)\ThirdParty\Qt\4.8.0\mkspecs\win32-msvc2010" -D_MSC_VER=1600 -DWIN32 EditToolImpl.h -o generated\moc_EditToolImpl.cpp
Generated moc_EditToolImpl.cpp
@
/****************************************************************************
** Meta object code from reading C++ file 'EditToolImpl.h'
**
** Created: Tue Feb 7 19:19:52 2012
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.0)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/#include "../EditToolImpl.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'EditToolImpl.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 63
#error "This file was generated using the moc from 4.8.0. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endifQT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_EditToolImpl[] = {// content:
6, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount// slots: signature, parameters, type, tag, flags
14, 13, 13, 13, 0x0a,0 // eod
};
static const char qt_meta_stringdata_EditToolImpl[] = {
"EditToolImpl\0\0colorToolButtonClicked()\0"
};void EditToolImpl::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
EditToolImpl *_t = static_cast<EditToolImpl *>(_o);
switch (_id) {
case 0: _t->colorToolButtonClicked(); break;
default: ;
}
}
Q_UNUSED(_a);
}const QMetaObjectExtraData EditToolImpl::staticMetaObjectExtraData = {
0, qt_static_metacall
};const QMetaObject EditToolImpl::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_EditToolImpl,
qt_meta_data_EditToolImpl, &staticMetaObjectExtraData }
};#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &EditToolImpl::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATIONconst QMetaObject *EditToolImpl::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}void EditToolImpl::qt_metacast(const char _clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_EditToolImpl))
return static_cast<void>(const_cast< EditToolImpl>(this));
return QObject::qt_metacast(_clname);
}int EditToolImpl::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
}
return _id;
}
QT_END_MOC_NAMESPACE
@The crash occurs within the connect call indicating that the call to *EditToolImpl::metaObject() is returning NULL data.