Menu
  • HOME
  • TAGS

Why QObject needs to be the first in case of multiple inheritance

c++,qt,inheritance,qobject,moc

Assume that we have a class Test declared as: class Test : public Foo, public QObject { Q_OBJECT [..] }; If you take a look at the moc_test.cpp file that the moc tool has generated, you will see something like: [..] const QMetaObject Command::staticMetaObject = { { &Foo::staticMetaObject, qt_meta_stringdata_Command, qt_meta_data_Command,...

How do I cast QML items to corresponding C++ Item in Qt Quick

c++,qt,qtquick2,qobject,qtquickcontrols

Q: but I'm after the compile time checking that casting offers. qobject_cast does not offer any compilation-time checking. It is all runtime and dynamic, thus this request is not plausible. The context property is fine, or you could also get the class name with QMetaObject. Then, you could build...

How to have button as signal and table as slot in Qt?

c++,qt,qtcore,qobject,qt-signals

This is very ismple. You would use Qt signal slot mechanism for this. You need to connect the button's clicked signal to your update handler slot for the database. #include <QObject> #include <QPushButton> ... class UpdateHandler : public QObject { Q_OBJECT public: explicit UpdateHandler(QObject *parent) : QObject(parent) { connect(&m_pushButton, SIGNAL(clicked(bool)),...

Qt: Segmentation fault with qobject_cast

c++,qt,qt5,qobject

The problem is in this function: void test_cast(QObject *returnedObject) { QTimer *timer = new QTimer; timer->setInterval(500); returnedObject = timer; //<-- changes the returnObject } You actually do not change the obj pointer passed to the test_cast function, but modify it's copy (returnedObject). As a result, the obj pointer in the...

Error only when building Qt project from command line

c++,qt,qmake,qobject,qt-signals

Found the problem...I was building a Qt5.5 project with qmake version 4...

How to check whether or not a dynamic property exists

c++,qt,qt5,qtcore,qobject

If the property doesn't exist, the QObject::property method returns an invalid variant. This is documented. Thus: QVariant filePath = activeWindow->property("filePath"); if (filePath.isValid()) { ... } Side note: comparing anything to true is either completely superfluous, or a sign of broken design somewhere. You should not have ... == true nor...

Swap Qt Widgets

c++,qt,polymorphism,swap,qobject

You should not be passing MainWindow1 and MainWindow2 pointers to swap like below. MainWindow1* w1 = new MainWindow1(); MainWindow2* w2 = new MainWindow2(); swap(&w1, &w2); If swap could happen in this case, MainWindow1 pointer would point to a MainWindow2 object, which is not right. You have to pass MainWindow pointers...

Expose QList hierarchy to QML

c++,qml,qobject,qlist

For exposing to QML lists of QObject-derived types, one should use QQmlListProperty rather than QList<T> as the property type MyClass.h: Q_PROPERTY (QQmlListProperty<MySubClass> objectList READ getMySubClassList NOTIFY objectListChanged) public: QQmlListProperty<MySubClass> getMySubClassList() { return QQmlListProperty<MySubClass>(this, 0, &MyClass::countMySubClassList, &MyClass::atMySubClassList); } static int countMySubClassList(QQmlListProperty<MySubClass> *property) { MyClass *m =...

QFileDialog - need correct

c++,qt,qobject,qfiledialog

The file dialog appears first before main window, and I don't know why. The reason why is because the window->show() command is not entirely synchronous -- that is, when you call window->show(), it posts some events into the event loop's event-queue, so that they can be acted on during...

No matching function for QObject::connect

c++,qt,qtcore,qobject,qt-signals

There can be several reasons for the issue in general: You do not inherit QObject. You do not have the Q_OBJECT macro in your class. You do not define the method as slot in your header file where the class is declared. Your issue is the first which can be...

Use connect() and tr() without QObject::

c++,qt,qobject

It can be done when you're in a member function of a class inheriting from QObject. And when you're not in scope of an object inheriting from QObject, you should use the object instance and not scoping. So for example: class MyClass : public QObject { ... void myMemberFunction() {...

QGLWidget context destruction

c++,qt,opengl,qobject,qglwidget

You could delete the Mesh object explicitly in the destructor of your QGLWidget derived class, because everything you put in there would be executed before ~QGLWidget() itself (and before ~QObject() which is responsible for the deletion of child objects). Or you can make the object a non-pointer member, or wrap...

Viber program stopped working log file: start timer Timers can only be used with threads started with QThread 1

qt,qobject,viber

Find Viber's installation folder (C:\Users\<username>\AppData\Local\Viber on Windows 8), navigate to the folder with the name of the latest downloaded version (5.1.1.15 in my case), and run ViberSetup.exe. This should update it to the latest version, keeping your data and resolving the issue.

Communication with QThread not working with Signals / Slots

c++,qt,signals-slots,qthread,qobject

Thanks for the input. I solved it by having a singleton that has a flag that the processing loop in my worker object in the QThread reads each loop iteration. It is protected by a QReadWrite lock. int UdpThreadController::killUdpThread(int frameType) { #if SINGLETON_CAMERA_UDP_DEBUG qDebug() << "Killing Thread! Frame type is:...

How to return QSqlQueryModel from a function in C++?

c++,qt,qobject,qtsql,qsqlquery

/usr/include/qt4/QtCore/qabstractitemmodel.h:360:5: error: ‘QAbstractTableModel::QAbstractTableModel(const QAbstractTableModel&)’ is private That error message means that you are trying to copy a QObject which does not quite have the "value" semantics, but more like "identity". QObjects are inherently not copyable. The reason is that what would you do with the parent/child hierarchy in such...

Signal/Slot Error on Compilation [closed]

c++,qt,qtcore,qobject,qt-signals

.\PBSPPTimeDelayServer.cpp(234) : error C3861: 'sig_tickExpicit': identifier not found and void sig_tickExplicit(const quint64 nNT); Basically, try to search for one of them and you will not find the other. That usually means, you have made a typo. I think what you meant to write is this (note the missing character...

Ambiguous destructor for QObject?

qt,destructor,qobject

Warning: Deleting a QObject while pending events are waiting to be delivered can cause a crash. You must not delete the QObject directly if it exists in a different thread than the one currently executing. You're focussing on the first statement of that sentence and ignoring the second. This...