qobject

forced to use QT5_WRAP_CPP macro instead of automoc property in cmake

拜拜、爱过 提交于 2019-12-11 09:52:39
问题 According to the cmake documentation I should be able to only use a property rather than having to wrap my header files, which contain a Q_OBJECT macro like in the following cmake snippet. If I use the wrapping macro the code compiles and runs but if I use only the enabled property, I get a compiler error ../gui/libgui.so: undefined reference to `vtable for ImageWidget' why is that? cmake_minimum_required (VERSION 3.5.1 FATAL_ERROR) project (app) #QT5_WRAP_CPP(MOC_files # ../gui/include/gui

Problems with QObject multiple inheritance and policy/traits design in C++

拟墨画扇 提交于 2019-12-11 07:35:32
问题 I'm building a fairly large plugin-driven app in my spare time, and have come across a show stopping design flaw. My app uses policy/traits based design, but because I use Qt it is done just through MI (rather than templates and MI). Some of these classes are pure virtual and some perform rather critical functions under the hood that the end-user should never touch. My problem is that some of these classes require signals/slots and therefore derive from QObject, no problem I can just

Compiling QObject-derived class on the command line on Linux

你。 提交于 2019-12-11 04:03:54
问题 I am new to Qt. I am trying to compile a small code snippet shown below: #include<QtCore/QtCore> #include<QtCore/QObject> class Test:public QObject { Q_OBJECT public: Test(){qDebug()<<"CTOR";} }; int main() { Test t; return 0; } I am trying to run it through command line using the following command: g++ -o signalTest.exe -l QtCore signalTest.cpp However I am getting the following error: undefined reference to vtable for Test I think I need to include the library for QObject , but I am not

Why is QObject ::findChildren returning children with a common base class?

ぃ、小莉子 提交于 2019-12-10 20:21:35
问题 I am using QObject as a base class for a composite pattern. Say I have a parent class File (in a contrived example) to which I am adding children of different types, HeaderSection and PageSection. File, HeaderSection and PageSection are all Sections. The constructor for Section takes a parent object which is passed through to QObject's constructor, setting the parent. e.g: class Section : public QObject { Q_OBJECT // parent:child relationship gets set by QObject Section(QString name, Section

Export QObject-based class to DLL

陌路散爱 提交于 2019-12-10 15:16:06
问题 I'm composing a class which derives from QObject, and I want to export this class into a DLL file so other applications can use it. But I got some mysterious problem here: The code is shown below: mydll.h: #ifndef MYDLL_H #define MYDLL_H #include "mydll_global.h" #include <QObject> #include <QDebug> class MYDLLSHARED_EXPORT MyDll : public QObject { Q_OBJECT public: explicit MyDll(QObject * parent = 0); void test() const; }; #endif // MYDLL_H mydll_global.h: #ifndef MYDLL_GLOBAL_H #define

How to force PyQt5 use for QObject class?

送分小仙女□ 提交于 2019-12-10 13:54:24
问题 I'm developping a small graphic application using Python 3 and PyQt5. On the first computer I use, where only PyQt5 is installed, everything in my code is fine. But when I want to run my code on my other laptop, where both PyQt4 and PyQt5 are installed, I get the following error: RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class Python interpreter locates the error in the file "ViewWindow.py", called from the main file. As I have both PyQt4 and PyQt5 on this

Any chance to use non QObject classes with QML

回眸只為那壹抹淺笑 提交于 2019-12-09 13:16:00
问题 As of Exposing Attributes of C++ Types to QML classes used with QML have to be QObject s. Any chance I can use non QObjects s (aka POCO, not derived from QObject , but registered with Qt metasystem)? If not, is there a simple generic wrapping system to make my objects QML compliant. One I can think of is to add dynamic properties to a simple QObject . Or is there a way to implicitly convert to a QML compliant type so I do not need to wrap at all? 回答1: This is one hot topic actually. I believe

View, edit and update data (from C++ ) in QML with multiple views, while the Data stays in C++ (subscribe to data)

和自甴很熟 提交于 2019-12-08 00:12:20
问题 I have some data stored in instances of a C++ class (Data.cpp). Now i want to be able to view and edit this data from 2 seperate representations in QML, so that if the values in View1 are changed, the data itself (C++) is changed and the value displayed by View2 as well (because it gets notified when the C++ data changes). Here is what I got so far: Data.h class Data : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) public: Data(std::string name);

What is the right way for an object to have a collection of a QObject derived class?

六眼飞鱼酱① 提交于 2019-12-07 18:18:48
问题 I'm trying to make a class exposing a collection(or several) of a QObject derived class(with its own qt properties) qt properties I can use in qml. According to http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#no-copy-constructor-or-assignment-operator qt doesn't play well with copy constructors. So I used QList<QObject derived class> (my first idea) I can't pass the list by reference(or at least I think thats what the compiler errors implies)(needs copies) and am having a hard time

Temporarily block signals between two QObjects

点点圈 提交于 2019-12-07 05:43:51
问题 I would like to generically and temporarily block the signals between two QObjects without modifying the other signals/slots behavior, and without knowing their contexts. Something like QObject::blockSignals(bool), but only acting between two QObjects . That is, implementing the following SignalBlocker::blockSignals(bool) function: class SignalBlocker { public: SignalBlocker(QObject *sender, QObject *receiver) : mSender(sender), mReceiver(receiver) {} void blockSignals(bool block); private: