qt-signals

How to connect in Qt signal and slot in dynamically added buttons to get in slot index of added button?

对着背影说爱祢 提交于 2019-12-08 06:26:00
问题 I have list with pointers QPushButton: QList<QPushButton*> listButtons; In this code I am adding dynamically buttons listButtons.push_back(new QPushButton("Cancel", this)); connect(listButtons.last(), SIGNAL (clicked(listButtons.size)), this, SLOT(handleButton(int))); //this doesn't work How can I also save index of every button, so I can keep track, what button user clicked, because every button has to cancel specific task. I use C++98, so I can not use Lambda function 回答1: You have to use

Why Qt signal will not work after use class as property in qml page?

ⅰ亾dé卋堺 提交于 2019-12-08 06:06:59
问题 I have a c++ class like below and i used this class after registering that in an qml page and that signals works well in qml page class1.cpp QString Class1::message(){ return m_Message; } void Class1::setMessage(QString m){ m_Message=m ; emit messageChanged(); } void Class1::invokeEvent(){ setMessage("The Second Message"); } Class2* Class1::getClass2Obj(){ class2obj.plusplusClickCount(); return &class2obj; } class1.h class Class1 : public QObject { Q_OBJECT QString m_Message; Class2 class2obj

Why Qt signal will not work after use class as property in qml page?

谁说我不能喝 提交于 2019-12-07 17:44:32
I have a c++ class like below and i used this class after registering that in an qml page and that signals works well in qml page class1.cpp QString Class1::message(){ return m_Message; } void Class1::setMessage(QString m){ m_Message=m ; emit messageChanged(); } void Class1::invokeEvent(){ setMessage("The Second Message"); } Class2* Class1::getClass2Obj(){ class2obj.plusplusClickCount(); return &class2obj; } class1.h class Class1 : public QObject { Q_OBJECT QString m_Message; Class2 class2obj; public: explicit Class1(QObject *parent = nullptr); Q_PROPERTY(QString message READ message WRITE

Connecting signal to slot between classes in PyQt

牧云@^-^@ 提交于 2019-12-06 17:05:45
问题 Aim is to connect a signal of the top class TicTacToe with the QMainWindow class. It throws an error: TicTacToe cannot be converted to PyQt5.QtCore.QObject in this context #!/usr/bin/env python from PyQt5.QtCore import (QLineF, QPointF, QRectF, pyqtSignal) from PyQt5.QtGui import (QIcon, QBrush, QColor, QPainter, QPixmap) from PyQt5.QtWidgets import (QAction, QMainWindow, QApplication, QGraphicsView, QGraphicsScene, QGraphicsItem, QGridLayout, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit,

Q_ENUMS are “undefined” in QML?

跟風遠走 提交于 2019-12-05 08:26:36
Enums are not working out for me. I have registered them with Q_ENUMS() I did not forget the Q_OBJECT macro the type is registered using qmlRegisterType() the module is imported in QML In short, everything is "by-the-book" but for some reason I continue getting undefined for each and every enum in QML. Am I missing something? class UI : public QQuickItem { Q_OBJECT Q_ENUMS(ObjectType) public: enum ObjectType { _Root = 0, _Block }; ... }; ... qmlRegisterType<UI>("Nodes", 1, 0, "UI"); ... import Nodes 1.0 ... console.log(UI._Root) // undefined EDIT: Also note that the registered enums are indeed

Connecting signal to slot between classes in PyQt

筅森魡賤 提交于 2019-12-04 22:13:12
Aim is to connect a signal of the top class TicTacToe with the QMainWindow class. It throws an error: TicTacToe cannot be converted to PyQt5.QtCore.QObject in this context #!/usr/bin/env python from PyQt5.QtCore import (QLineF, QPointF, QRectF, pyqtSignal) from PyQt5.QtGui import (QIcon, QBrush, QColor, QPainter, QPixmap) from PyQt5.QtWidgets import (QAction, QMainWindow, QApplication, QGraphicsView, QGraphicsScene, QGraphicsItem, QGridLayout, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton) class TicTacToe(QGraphicsItem): def __init__(self): super(TicTacToe, self).__init__() def

Qt multiple inheritance and signals

感情迁移 提交于 2019-12-04 11:46:02
问题 I'm having a problem with QT regarding multiple enheritance because of QObject. I know that a lot of others have the same problems but I don't know how I should fix it. class NavigatableItem : public QObject { Q_OBJECT signals: void deselected(); void selected(); void activated(); }; class Button : public NavigatableItem, public QToolButton { Q_OBJECT ... } class MainMenuOption : public Button { Q_OBJECT ... } When I do this MainMenuOption* messages = new MainMenuOption(); connect(messages,

How to detect Windows shutdown or logoff in Qt

佐手、 提交于 2019-12-04 07:17:56
I am porting a Linux app to Windows written in Qt. The application needs to save some settings before closing. On Linux, we can do that by signal handlers for SIGTERM etc. How can I implement the same on Windows. If you are using the Qt event loop, you can catch the following signal: void QCoreApplication::aboutToQuit() [signal] This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session. The signal

qt signal undefined reference error

試著忘記壹切 提交于 2019-12-03 15:41:30
问题 I have a class server for which I have created a signal joined(QString name). I call it in a function called join(QString name), however I'm getting the error Server.o: In function Server::join(QString)': Server.cpp:(.text+0x48): undefined reference to Server::joined(QString)' collect2: ld returned 1 exit status This is what my header file looks like: #ifndef SERVER_H #define SERVER_H #include <QString> #include <mqueue.h> #include <QVector> #include <QStringList> #include "../src/messages.h"

Qt multiple inheritance and signals

五迷三道 提交于 2019-12-03 07:17:15
I'm having a problem with QT regarding multiple enheritance because of QObject. I know that a lot of others have the same problems but I don't know how I should fix it. class NavigatableItem : public QObject { Q_OBJECT signals: void deselected(); void selected(); void activated(); }; class Button : public NavigatableItem, public QToolButton { Q_OBJECT ... } class MainMenuOption : public Button { Q_OBJECT ... } When I do this MainMenuOption* messages = new MainMenuOption(); connect(messages, SIGNAL(selected()), SLOT(onMenuOptionSelected())) I will get the error: QObject' is an ambiguous base of