qobject

Difference between QObject::connect vs connect methods

只谈情不闲聊 提交于 2019-11-30 01:26:04
问题 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? 回答1: You call the static version in both aforementioned cases,

PyQt: RuntimeError: wrapped C/C++ object has been deleted

放肆的年华 提交于 2019-11-29 09:28:51
If I run this code: #!/usr/local/bin/ python3 import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Window(QMainWindow): def __init__(self): super().__init__() self.button1 = QPushButton("1") self.button2 = QPushButton("2") self.setCentralWidget(self.button1) self.button1.clicked.connect(lambda: self.setCentralWidget(self.button2)) self.button2.clicked.connect(lambda: self.setCentralWidget(self.button1)) self.show() if __name__ == '__main__': import sys app = QApplication(sys.argv) window = Window() sys.exit(app.exec_()) ...I get this output: Traceback (most recent call last):

Is it possible to mix template-derived C++ classes with Qt's Q_OBJECT?

懵懂的女人 提交于 2019-11-29 02:00:15
In my application, I have the following class hierarchy: class Word { ... } template <typename T> class Dictionary { ... }; class WordDictionary : public Dictionary<Word> { Q_OBJECT ... } The WordDictionary class parses a dictionary which takes a long time. I am running the parsing function from within a separate thread and I want it to be able to signal the GUI thread from time to time to provide progress updates based on the current line number being parsed. That's why I want it to be a Q_OBJECT. I tried to make the base class Dictionary a Q_OBJECT but got a message that Q_OBJECT templates

Qt interfaces or abstract classes and qobject_cast()

耗尽温柔 提交于 2019-11-29 00:45:42
问题 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

How can I create a new window from within QML?

[亡魂溺海] 提交于 2019-11-28 07:37:20
Is there a way to create a completely new window instance, as a child window of the main QML window in a QmlApplication? // ChildWindow.qml Rectangle { id: childWindow width: 100 height: 100 // stuff } // main.qml Rectangle { id: window width: 1000 height: 600 MouseArea { anchors.fill: parent onClicked: createAWindow(childWindow); } } I am trying to avoid writing a Q_OBJECT class just for instanciating the new window within a new QmlApplicationViewer . There is no way to create top-level windows using only built-in QML functionality. However there's a project on Qt Labs called Desktop

PyQt: RuntimeError: wrapped C/C++ object has been deleted

独自空忆成欢 提交于 2019-11-28 02:44:25
问题 If I run this code: #!/usr/local/bin/ python3 import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Window(QMainWindow): def __init__(self): super().__init__() self.button1 = QPushButton("1") self.button2 = QPushButton("2") self.setCentralWidget(self.button1) self.button1.clicked.connect(lambda: self.setCentralWidget(self.button2)) self.button2.clicked.connect(lambda: self.setCentralWidget(self.button1)) self.show() if __name__ == '__main__': import sys app = QApplication(sys

Is it possible to mix template-derived C++ classes with Qt's Q_OBJECT?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 16:18:40
问题 In my application, I have the following class hierarchy: class Word { ... } template <typename T> class Dictionary { ... }; class WordDictionary : public Dictionary<Word> { Q_OBJECT ... } The WordDictionary class parses a dictionary which takes a long time. I am running the parsing function from within a separate thread and I want it to be able to signal the GUI thread from time to time to provide progress updates based on the current line number being parsed. That's why I want it to be a Q

Unresolved external symbol \"public: virtual struct QMetaObject const * __thiscall Parent

邮差的信 提交于 2019-11-27 10:47:10
I inherited a class from QObject : class Parent: public QObject { Q_OBJECT QObject* cl; public: Parent(QObject *parent=0):QObject(parent) { cl = NULL; } QObject* getCl() const { return cl; } void setCl(QObject *obj) { cl = obj; } }; But when I write : Parent ev; I get the following error: main.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Parent::metaObject(void)const " (?metaObject@Parent@@UBEPBUQMetaObject@@XZ) main.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall Parent::qt_metacast(char const *

How heavy is QObject really? [duplicate]

北慕城南 提交于 2019-11-27 03:14:38
问题 This question already has answers here : Getting the size of a Qt Object (4 answers) How big is QObject? [duplicate] Closed 6 years ago . I recently posted a question about the overhead of QObject in typical usage scenarios, but unfortunately the question got closed as a duplicate of another question that didn't technically answer the question. What is worse, the hasty "Samaritans" who politely rushed to close my question interrupted the answer I was just finishing typing after running a few

How do I copy object in Qt?

雨燕双飞 提交于 2019-11-27 02:05:55
I'm using Qt and have some real basic problems. I have created my own widget MyTest that have a variable obj . I need to set this variable obj from an object outside of the widget so that the variable is copied not just a pointer to another object. I get an error message and can't figure out how to do this basic stuff. This is the code I'm using: MyTest.h: class MyTest : public QWidget { Q_OBJECT public: void setObj(QObject &inobj); QObject obj; .... } MyTest.cpp: void MyTest::setObj(QObject &inobj) { obj = inobj; //HERE I get the error message: "illegal access from 'QObject' to protected