qobject

QObject based class has a queued connection to itself

北城以北 提交于 2019-12-01 18:40:21
问题 I was digging into some source code I am working on. I found a peculiar statement that someone had coded. The source code is a GUI application with a QML GUI and uses QT 4.7.x. The snippet below belongs to core application logic. // connect signal-slots for decoupling QObject::connect (this, SIGNAL(setCurrentTaskSignal(int)), this, SLOT(SetCurrentTaskSlot(int)), Qt::QueuedConnection); It's strange that the object connects to itself via a queued connection which essentially means that the

QObject based class has a queued connection to itself

纵然是瞬间 提交于 2019-12-01 18:19:41
I was digging into some source code I am working on. I found a peculiar statement that someone had coded. The source code is a GUI application with a QML GUI and uses QT 4.7.x. The snippet below belongs to core application logic. // connect signal-slots for decoupling QObject::connect (this, SIGNAL(setCurrentTaskSignal(int)), this, SLOT(SetCurrentTaskSlot(int)), Qt::QueuedConnection); It's strange that the object connects to itself via a queued connection which essentially means that the object may "live" in different threads at the same time? At first glance It didn't made any sense to me.

Why won't this compile (link) with the Q_OBJECT macro in place?

允我心安 提交于 2019-12-01 08:13:59
I made a prototype of a project with PyQt and made it work there, now I'm trying to convert it to C++ and am having some problems. If I don't put the Q_OBJECT macro in, it compiles and works, but if I comment it out, I get the following errors: Undefined symbols: "vtable for MapView", referenced from: MapView::~MapView()in mapview.o MapView::~MapView()in mapview.o MapView::MapView(QObject*)in mapview.o MapView::MapView()in mapview.o "MapView::staticMetaObject", referenced from: MapView::MapView(QObject*)in mapview.o MapView::MapView()in mapview.o Here's the header: #ifndef MAPVIEW_H #define

Why won't this compile (link) with the Q_OBJECT macro in place?

纵饮孤独 提交于 2019-12-01 06:40:45
问题 I made a prototype of a project with PyQt and made it work there, now I'm trying to convert it to C++ and am having some problems. If I don't put the Q_OBJECT macro in, it compiles and works, but if I comment it out, I get the following errors: Undefined symbols: "vtable for MapView", referenced from: MapView::~MapView()in mapview.o MapView::~MapView()in mapview.o MapView::MapView(QObject*)in mapview.o MapView::MapView()in mapview.o "MapView::staticMetaObject", referenced from: MapView:

Repeating Q_DISABLE_COPY in QObject derived classes

走远了吗. 提交于 2019-12-01 02:37:05
In Qt there is a macro that allows declaring private copy constructurs and assignment operators for classes: http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#Q_DISABLE_COPY It is said that this macro should be used for all QObject (especially QWidget) derived classes. I understand how this works and why it is useful. What I do not understand: Is there any reason to repeat Q_DISABLE_COPY in my QObject derived classes while QObject already contains Q_DISABLE_COPY and through this effectively prevents my derived classes from being copied? The error message that might be printed from

Difference between QObject::connect vs connect methods

跟風遠走 提交于 2019-11-30 17:36:18
I am a newbie with Qt. Most of the times Qt developers need to use signals and slots for object communication. I have seen two ways of connecting signals and slots so far. 1)QObject::connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int))); 2)connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int))); What is the exact difference between both of them? Why do we have to prefix QObject in the first method? lpapp You call the static version in both aforementioned cases, the signature of which is as follows: QMetaObject::Connection QObject::connect(const QObject * sender,

Should non-QObject derived classes “always” be put on the stack?

回眸只為那壹抹淺笑 提交于 2019-11-30 15:46:23
问题 Coming from the Symbian world, I'm used to using the heap as much as possible to avoid running out of stack space, especially when handling descriptors. CBase derived classes were always dynamically allocated on the heap, since if they were not, their member variables would stay uninitialized. Does the same convention apply to QObject-derived classes? In Qt it seems to be common to put, for example QString, on the stack. Are the string contents put on the heap while QString acts as a

Should non-QObject derived classes “always” be put on the stack?

江枫思渺然 提交于 2019-11-30 14:52:40
Coming from the Symbian world, I'm used to using the heap as much as possible to avoid running out of stack space, especially when handling descriptors. CBase derived classes were always dynamically allocated on the heap, since if they were not, their member variables would stay uninitialized. Does the same convention apply to QObject-derived classes? In Qt it seems to be common to put, for example QString, on the stack. Are the string contents put on the heap while QString acts as a container on the stack, or is everything put on the stack? Frank Osterfeld As sje397 said: It's idiomatic to

Q_OBJECT linker error!

空扰寡人 提交于 2019-11-30 12:24:18
I am receiving the following linker error when I build my application. HIMyClass.obj:: error: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CHIMyClass::metaObject(void)const " (?metaObject@CHIMyClass@@UBEPBUQMetaObject@@XZ) File not found : HIMyClass.obj HIMyClass.obj:: error: unresolved external symbol "public: virtual void * __thiscall CHIMyClass::qt_metacast(char const *)" (?qt_metacast@CHIMyClass@@UAEPAXPBD@Z) File not found : HIMyClass.obj HIMyClass.obj:: error: unresolved external symbol "public: virtual int __thiscall CHIMyClass::qt_metacall(enum

Qt interfaces or abstract classes and qobject_cast()

主宰稳场 提交于 2019-11-30 03:04:40
I have a fairly complex set of C++ classes that are re-written from Java. So each class has a single inherited class, and then it also implements one or more abstract classes (or interfaces). Is it possible to use qobject_cast() to convert from a class to one of the interfaces? If I derive all interfaces from QObject , I get an error due to ambiguous QObject references. If however, I only have the base class inherited from QObject , I can't use qobject_cast() because that operates with QObject s. I'd like to be able to throw around classes between plugins and DLLs referred to by their