Qt-interest Archive, October 2007
problems with qRegisterMetaType
Message 1 in thread
hi,
im have a problem with qRegisterMetaType ...
i want to connenct a object in thread a to an object with thread b. the
signal and slot has as parameter an custom type. i use queued connections,
and therefore i have to register my custom type at qt's meta type. the code
looks like this ...
qRegisterMetaType<ThException>("ThException");
if ( !QObject::connect(this,
SIGNAL(showCalled(const ThException&)),
&ThExceptionHandlerDialog::get(),
SLOT(showException(const ThException&)),
Qt::QueuedConnection) )
{
ThLogBase::logError("QObject::connect failed!");
}
the connecting is ok, but when the signal is emited, my application breakes
down. i thought i made everything right (ThException has default
constructor, copy constructor, default destructor, ..., as descriped in the
doc), but somehow i don't!
if i'm trying it with QString (or any other defined meta type) it works
fine!
i would be glad if someone could help me!
peter
Message 2 in thread
Peter Hausberger wrote:
> hi,
>
> im have a problem with qRegisterMetaType ...
>
> i want to connenct a object in thread a to an object with thread b.
> the signal and slot has as parameter an custom type. i use queued
> connections, and therefore i have to register my custom type at qt's
> meta type. the code looks like this ...
>
> qRegisterMetaType<ThException>("ThException");
> if ( !QObject::connect(this,
> SIGNAL(showCalled(const ThException&)),
> &ThExceptionHandlerDialog::get(),
> SLOT(showException(const ThException&)),
>
> Qt::QueuedConnection)
> )
> {
> ThLogBase::logError("QObject::connect failed!");
> }
>
> the connecting is ok, but when the signal is emited, my application
> breakes down. i thought i made everything right (ThException has
> default constructor, copy constructor, default destructor, ..., as
> descriped in the doc), but somehow i don't!
> if i'm trying it with QString (or any other defined meta type) it
> works fine!
>
> i would be glad if someone could help me!
>
Did you use Q_DECALRE_METATYPE() after the class declaration?
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 3 in thread
We'll need a minimal compilable example to figure this out. The obvious
has been ruled out....
--Justin
Peter Hausberger wrote:
> ... yes i used it (although in the doc is written, that you don't have
> to in this case, i don't know). i can't imagine where's the problem?!
>
> 2007/10/8, Justin Noel < justin@xxxxxxx <mailto:justin@xxxxxxx>>:
>
> Peter Hausberger wrote:
> > hi,
> >
> > im have a problem with qRegisterMetaType ...
> >
> > i want to connenct a object in thread a to an object with thread b.
> > the signal and slot has as parameter an custom type. i use queued
> > connections, and therefore i have to register my custom type at qt's
> > meta type. the code looks like this ...
> >
> > qRegisterMetaType<ThException>("ThException");
> > if ( !QObject::connect(this,
> > SIGNAL(showCalled(const ThException&)),
> > &ThExceptionHandlerDialog::get(),
> > SLOT(showException(const ThException&)),
> >
> > Qt::QueuedConnection)
> > )
> > {
> > ThLogBase::logError("QObject::connect failed!");
> > }
> >
> > the connecting is ok, but when the signal is emited, my application
> > breakes down. i thought i made everything right (ThException has
> > default constructor, copy constructor, default destructor, ..., as
> > descriped in the doc), but somehow i don't!
> > if i'm trying it with QString (or any other defined meta type) it
> > works fine!
> >
> > i would be glad if someone could help me!
> >
>
> Did you use Q_DECALRE_METATYPE() after the class declaration?
>
> --Justin
>
>
>
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 4 in thread
class ThException : public QObject
{
Q_OBJECT
public:
ThException() {};
ThException(const ThException& p_rcoEcxeption) {};
~ThException() {};
const QString& getTitle() const;
const QString& getDescription() const;
void show() const { emit showCalled(*this); };
signals:
void showCalled(const ThException& p_rcoException) const;
};
Q_DECLARE_METATYPE(ThException)
class ThExceptionDialog : public QMessageBox
{
Q_OBJECT
public:
public slots:
void showException(const ThException& p_rcoException) {
setText(p_rcoException.getTitle() + "\n" + p_rcoException.getDescription());
show(); };
};
2007/10/8, Justin Noel <justin@xxxxxxx>:
>
>
> We'll need a minimal compilable example to figure this out. The obvious
> has been ruled out....
>
> --Justin
>
> Peter Hausberger wrote:
> > ... yes i used it (although in the doc is written, that you don't have
> > to in this case, i don't know). i can't imagine where's the problem?!
> >
> > 2007/10/8, Justin Noel < justin@xxxxxxx <mailto:justin@xxxxxxx>>:
> >
> > Peter Hausberger wrote:
> > > hi,
> > >
> > > im have a problem with qRegisterMetaType ...
> > >
> > > i want to connenct a object in thread a to an object with thread
> b.
> > > the signal and slot has as parameter an custom type. i use queued
> > > connections, and therefore i have to register my custom type at
> qt's
> > > meta type. the code looks like this ...
> > >
> > > qRegisterMetaType<ThException>("ThException");
> > > if ( !QObject::connect(this,
> > > SIGNAL(showCalled(const ThException&)),
> > > &ThExceptionHandlerDialog::get(),
> > > SLOT(showException(const ThException&)),
> > >
> > > Qt::QueuedConnection)
> > > )
> > > {
> > > ThLogBase::logError("QObject::connect failed!");
> > > }
> > >
> > > the connecting is ok, but when the signal is emited, my
> application
> > > breakes down. i thought i made everything right (ThException has
> > > default constructor, copy constructor, default destructor, ..., as
> > > descriped in the doc), but somehow i don't!
> > > if i'm trying it with QString (or any other defined meta type) it
> > > works fine!
> > >
> > > i would be glad if someone could help me!
> > >
> >
> > Did you use Q_DECALRE_METATYPE() after the class declaration?
> >
> > --Justin
> >
> >
> >
>
>
>
Message 5 in thread
Not to fuss, but I'll need files that compile including main and a .pro.
Most of us answer this list in our free time. I just don't t have the
time or drive to write an example app recreate your problem. Given the
files I can spend a few minutes poking around.
Thanks,
--Justin
Peter Hausberger wrote:
> class ThException : public QObject
> {
> Q_OBJECT
>
> public:
> ThException() {};
> ThException(const ThException& p_rcoEcxeption) {};
>
> ~ThException() {};
>
> const QString& getTitle() const;
> const QString& getDescription() const;
>
> void show() const { emit showCalled(*this); };
>
> signals:
> void showCalled(const ThException& p_rcoException) const;
> };
>
> Q_DECLARE_METATYPE(ThException)
>
> class ThExceptionDialog : public QMessageBox
> {
> Q_OBJECT
>
> public:
>
> public slots:
>
>
> void showException(const ThException& p_rcoException) {
> setText(p_rcoException.getTitle() + "\n" +
> p_rcoException.getDescription()); show(); };
> };
>
> 2007/10/8, Justin Noel <justin@xxxxxxx <mailto:justin@xxxxxxx>>:
>
>
> We'll need a minimal compilable example to figure this out. The
> obvious
> has been ruled out....
>
> --Justin
>
> Peter Hausberger wrote:
> > ... yes i used it (although in the doc is written, that you
> don't have
> > to in this case, i don't know). i can't imagine where's the
> problem?!
> >
> > 2007/10/8, Justin Noel < justin@xxxxxxx <mailto:justin@xxxxxxx>
> <mailto: justin@xxxxxxx <mailto:justin@xxxxxxx>>>:
> >
> > Peter Hausberger wrote:
> > > hi,
> > >
> > > im have a problem with qRegisterMetaType ...
> > >
> > > i want to connenct a object in thread a to an object with
> thread b.
> > > the signal and slot has as parameter an custom type. i use
> queued
> > > connections, and therefore i have to register my custom
> type at qt's
> > > meta type. the code looks like this ...
> > >
> > > qRegisterMetaType<ThException>("ThException");
> > > if ( !QObject::connect(this,
> > > SIGNAL(showCalled(const ThException&)),
> > > &ThExceptionHandlerDialog::get(),
> > > SLOT(showException(const ThException&)),
> > >
> > > Qt::QueuedConnection)
> > > )
> > > {
> > > ThLogBase::logError("QObject::connect failed!");
> > > }
> > >
> > > the connecting is ok, but when the signal is emited, my
> application
> > > breakes down. i thought i made everything right
> (ThException has
> > > default constructor, copy constructor, default destructor,
> ..., as
> > > descriped in the doc), but somehow i don't!
> > > if i'm trying it with QString (or any other defined meta
> type) it
> > > works fine!
> > >
> > > i would be glad if someone could help me!
> > >
> >
> > Did you use Q_DECALRE_METATYPE() after the class declaration?
> >
> > --Justin
> >
> >
> >
>
>
>
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 6 in thread
hi,
sorry, please forget my last entry ...
i created a small example code now (in an own sandbox), and somehow it works
...
so the error at my application must be somewhere else!
attached the code, if you are still interested ;-):
header:
#include "iostream"
#include <QObject>
#include <QMetaType>
#include <QMessageBox>
#include <QString>
#include <QThread>
#include <QApplication>
#include <QPushButton>
class ThException;
class ThExceptionDialog : public QMessageBox
{
Q_OBJECT
public:
static ThExceptionDialog& get() { if (!sm_pDialog) sm_pDialog = new
ThExceptionDialog; return *sm_pDialog; };
static void destroy() { delete sm_pDialog; };
public slots:
void showException(const ThException& p_rcoException);
private:
ThExceptionDialog() : QMessageBox(QMessageBox::Critical,
"ThExceptionDialog", "", QMessageBox::Ok) { std::cout << "creation"; };
~ThExceptionDialog() { std::cout << "destruction"; };
static ThExceptionDialog* sm_pDialog;
};
class ThException : public QObject
{
Q_OBJECT
public:
ThException() { qRegisterMetaType<ThException>("ThException"); if (
!QObject::connect(this, SIGNAL(showCalled(const ThException&)),
&ThExceptionDialog::get(), SLOT(showException(const ThException&))) )
std::cout << "Error at QObject::connect!"; };
ThException(const ThException& p_rcoEcxeption) {};
~ThException() {};
const QString getTitle() const { return "Title"; };
const QString getDescription() const { return "Description"; };
void show() const { emit showCalled(*this); };
signals:
void showCalled(const ThException& p_rcoException) const;
};
Q_DECLARE_METATYPE(ThException)
class MyThread : public QThread
{
public:
MyThread() {};
~MyThread() {};
private:
void run() { ThException oException; oException.show(); };
};
source:
#include "main2.h"
void ThExceptionDialog::showException(const ThException& p_rcoException)
{
setText(p_rcoException.getTitle() + "\n" +
p_rcoException.getDescription());
show();
};
ThExceptionDialog* ThExceptionDialog::sm_pDialog(0);
int main(int argc, char* argv[])
{
QApplication oCoreApplication(argc, argv);
QPushButton oButton("MyApplication");
oButton.show();
// create the object at the core thread
ThExceptionDialog::get();
MyThread oMyThread;
oMyThread.start();
oCoreApplication.exec();
std::cout << "end reached";
ThExceptionDialog::destroy();
return 0;
}
2007/10/8, Justin Noel <justin@xxxxxxx>:
> >
> >
> > We'll need a minimal compilable example to figure this out. The obvious
> > has been ruled out....
> >
> > --Justin
> >
> > Peter Hausberger wrote:
> > > ... yes i used it (although in the doc is written, that you don't have
> >
> > > to in this case, i don't know). i can't imagine where's the problem?!
> > >
> > > 2007/10/8, Justin Noel < justin@xxxxxxx <mailto: justin@xxxxxxx>>:
> > >
> > > Peter Hausberger wrote:
> > > > hi,
> > > >
> > > > im have a problem with qRegisterMetaType ...
> > > >
> > > > i want to connenct a object in thread a to an object with thread
> > b.
> > > > the signal and slot has as parameter an custom type. i use
> > queued
> > > > connections, and therefore i have to register my custom type at
> > qt's
> > > > meta type. the code looks like this ...
> > > >
> > > > qRegisterMetaType<ThException>("ThException");
> > > > if ( !QObject::connect(this,
> > > > SIGNAL(showCalled(const ThException&)),
> > > > &ThExceptionHandlerDialog::get(),
> > > > SLOT(showException(const ThException&)),
> > > >
> > > > Qt::QueuedConnection)
> > > > )
> > > > {
> > > > ThLogBase::logError("QObject::connect failed!");
> > > > }
> > > >
> > > > the connecting is ok, but when the signal is emited, my
> > application
> > > > breakes down. i thought i made everything right (ThException has
> > > > default constructor, copy constructor, default destructor, ...,
> > as
> > > > descriped in the doc), but somehow i don't!
> > > > if i'm trying it with QString (or any other defined meta type)
> > it
> > > > works fine!
> > > >
> > > > i would be glad if someone could help me!
> > > >
> > >
> > > Did you use Q_DECALRE_METATYPE() after the class declaration?
> > >
> > > --Justin
> > >
> > >
> > >
> >
> >
> >
>