signals-slots

How to call defined slots from keypress event in qt / How to connect keypressed event with QPushbutton on gui?

冷暖自知 提交于 2021-02-11 04:56:43
问题 I am beginner to qt. I was working on calculator gui application, I have already defined slots like numPressed() when any of the number pushbutton is pressed on the calculator that will be displayed on the lineEdit. void Calculator::numPressed(){ QPushButton *button = (QPushButton *)sender(); QString buttonValue = button->text(); Qstring display = ui->lineEdit->text(); Qdouble ProcessedValue = previousValue + buttonValue.toDouble(); . . . ui->lineEdit->setText(QString::number(ProcessedValue))

How to call defined slots from keypress event in qt / How to connect keypressed event with QPushbutton on gui?

情到浓时终转凉″ 提交于 2021-02-11 04:53:04
问题 I am beginner to qt. I was working on calculator gui application, I have already defined slots like numPressed() when any of the number pushbutton is pressed on the calculator that will be displayed on the lineEdit. void Calculator::numPressed(){ QPushButton *button = (QPushButton *)sender(); QString buttonValue = button->text(); Qstring display = ui->lineEdit->text(); Qdouble ProcessedValue = previousValue + buttonValue.toDouble(); . . . ui->lineEdit->setText(QString::number(ProcessedValue))

How to call defined slots from keypress event in qt / How to connect keypressed event with QPushbutton on gui?

折月煮酒 提交于 2021-02-11 04:52:57
问题 I am beginner to qt. I was working on calculator gui application, I have already defined slots like numPressed() when any of the number pushbutton is pressed on the calculator that will be displayed on the lineEdit. void Calculator::numPressed(){ QPushButton *button = (QPushButton *)sender(); QString buttonValue = button->text(); Qstring display = ui->lineEdit->text(); Qdouble ProcessedValue = previousValue + buttonValue.toDouble(); . . . ui->lineEdit->setText(QString::number(ProcessedValue))

Qt: Is there notification when event loop starts?

蓝咒 提交于 2021-02-07 04:54:25
问题 I have a Qt application with this kind of main()... int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWin; ... A separate, non-GUI thread is launched here mainWin.Init(); mainWin.show(); app.exec(); } This other thread that is created before the mainWin needs to know when it can start communicating with the mainWin. But since the mainWin uses Qt signals, slots, timers, etc, it's not truly ready to rock until the event loop is running (via exec()). My question is:

Cannot convert from pointer to base class to pointer to derived class

二次信任 提交于 2021-01-28 07:42:00
问题 In headers: class Clock : public QWidget { Q_OBJECT public: explicit Clock(QWidget *parent = 0); ...... } class ElecClock : virtual public Clock { Q_OBJECT public: explicit ElecClock(QWidget *parent = 0); private slots: void showTime(); //display two LCDNumber ...... } class MechClock : virtual public Clock { Q_OBJECT public: explicit MechClock(QWidget *parent = 0); ...... } class NewClock : public MechClock, public ElecClock //combination of Mechclock and ElecClock { Q_OBJECT public:

Qt signal slot button

纵饮孤独 提交于 2021-01-07 07:00:39
问题 I need to change my text in QLabel every time when I clicked in order to my info updates. When I change the value of A, the value of B must change, too. I have two button that can change values in two QLabel (value of A, value of B). main.cpp: Counter A, B; QObject::connect(&A, &Counter::changeValue, &B, &Counter::setValue); QObject::connect(&A, &Counter::changeValue, &B, &Counter::Increment); QObject::connect(&A, &Counter::changeValue, &B, &Counter::Decrement ); QObject::connect(Add,

Threading with QRunnable - Proper manner of sending bi-directional callbacks

和自甴很熟 提交于 2020-12-26 07:56:24
问题 From a tutorial, I've seen that signals and slots can be used to make callbacks from a worker thread into the main GUI thread, but I'm uncertain how to establish bi-directional communication using signals and slots. The following is what I am working with: class RespondedToWorkerSignals(QObject): callback_from_worker = pyqtSignal() class RespondedToWorker(QRunnable): def __init__(self, func, *args, **kwargs): super(RespondedToWorker, self).__init__() self._func = func self.args = args self

How to create a SIGNAL for QTableWidget from keyboard?

有些话、适合烂在心里 提交于 2020-12-12 06:27:32
问题 I have a table and move around inside with left, right, up, down buttons. Now I need to create a SIGNAL when I stay in a certain cell and press SPACE button. This SIGNAL should bring also the coordinate of that cell. I tried with standard signals of QTableWidget but it does not work. How can I solve this? 回答1: Create a separate header file i.e. "customtable.h" and then in the Designer you can Promote the existing QTableWidget to this class. class customTable:public QTableWidget { Q_OBJECT

How to create a SIGNAL for QTableWidget from keyboard?

非 Y 不嫁゛ 提交于 2020-12-12 06:24:05
问题 I have a table and move around inside with left, right, up, down buttons. Now I need to create a SIGNAL when I stay in a certain cell and press SPACE button. This SIGNAL should bring also the coordinate of that cell. I tried with standard signals of QTableWidget but it does not work. How can I solve this? 回答1: Create a separate header file i.e. "customtable.h" and then in the Designer you can Promote the existing QTableWidget to this class. class customTable:public QTableWidget { Q_OBJECT

Is it safe to emit signal passing QObject pointer as parameter right before the passed object is going to be destroyed?

懵懂的女人 提交于 2020-12-08 16:10:08
问题 Lets consider this simple example: Class Emitter: public QObject { ... signal: surfaceDestroyed(QObject*); public: void emittingMethod(QObject* surface) { emit surfaceDestroyed(surface); delete surface; } } I have a queued connection for this case connect(emitterObject, SIGNAL(surfaceDestroyed(QObject*), receiverObject, SLOT(onSurfaceDestroyed(QObject*)), Qt::QueuedConnection); In onSurfaceDestroyed method the received QObject is dereferenced and used So the question is how safe this code is?