signals-slots

QLabel click event using Qt?

让人想犯罪 __ 提交于 2019-12-30 08:52:06
问题 I'm new in Qt and have a question. I have QLabel and QLineEdit objects, and when QLabel text is clicked on, I want to set this text in QLineEdit . Also I have read that QLabel has not clicked signal. Can you explain how can I do this and write code for me ?! 回答1: Either style another type of QWidget such as a specific QPushButton to look like a QLabel and use its clicked() signal or inherit QLabel yourself and emit your own clicked() signal. See this example: https://wiki.qt.io/Clickable

Qt Signals and Slot connected twice… what happens?

天涯浪子 提交于 2019-12-28 12:15:30
问题 What happens if the same signal and slot is connected twice? How is the mechanism handled? 回答1: A few weeks ago, we had an intern accidentally connect a signal to a slot more than once. The idea was that under one condition, you'd have the slot connected to the signal, and under another condition you'd disconnect it. When you changed modes, you'd do the appropriate work. Well, he forgot to to disconnect when appropriate. So every time you changed modes, you had a new connection to the slot.

Qt Signals and Slot connected twice… what happens?

旧城冷巷雨未停 提交于 2019-12-28 12:15:11
问题 What happens if the same signal and slot is connected twice? How is the mechanism handled? 回答1: A few weeks ago, we had an intern accidentally connect a signal to a slot more than once. The idea was that under one condition, you'd have the slot connected to the signal, and under another condition you'd disconnect it. When you changed modes, you'd do the appropriate work. Well, he forgot to to disconnect when appropriate. So every time you changed modes, you had a new connection to the slot.

How signal and slots are implemented under the hood?

不羁岁月 提交于 2019-12-28 05:49:46
问题 This question is already asked in this forum but I don't understand the concept. I was reading around and it seems that signal and slots are implemented using function pointers i.e the signal is one big function which inside it calls all connected slots (function pointers). Is this correct? And what is the role of the generated moc files in the whole story? I don't understand how the signal function knows which slots to call i.e which slots are connected to this signal. Thanks for your time

Use UI array in a function Qt C++

天涯浪子 提交于 2019-12-25 18:14:42
问题 In my Windows forms code, ui is used to define graphical element by default. But I want to modify them in a function, like this: The problems is that the debug tool tells me that ui is not declared in this scope. #include <QMessageBox> #include <QFile> #include <QTextStream> #include "mainwindow.h" #include "ui_mainwindow.h" #include "datawindow.h" void getData(ui){ QFile inputFile("C:\\pepoles.txt"); if (inputFile.open(QIODevice::ReadOnly)){ QTextStream in(&inputFile); while ( !in.atEnd() ){

Is it valid to define a pure virtual signal in C++/Qt?

混江龙づ霸主 提交于 2019-12-25 04:29:44
问题 I am making an abstract-base-class and was thinking I might want a pure virtual signal. But when I compiled I get a warning for the pure virtual signals I have defined: ../FILE1.h:27: Warning: Signals cannot be declared virtual ../FILE1.h:28: Warning: Signals cannot be declared virtual Is it valid to define a pure virtual signal in C++/Qt? Is it valid to define a virtual signal? Qt's signal and slot documentation page says you can define virtual slots but doesn't talk about signals. I can't

QT Threading issues… something is stalling GUI response

陌路散爱 提交于 2019-12-25 03:55:44
问题 I'm having issues with QT threading somehow stalling the main GUI. To answer the first question... yes, QThread is not subclassed, and is done the "right way". The thread is run long-term (not a "do x then exit"), and it's main loop does have delays/sleeps. The threads main purpose is to collect data from elsewhere, compose an image, and transmit that image over a COM port. There are coding areas that i think could be creating the problem. Im using my own "sleep" function as msleep is not

How to connect signal to boost::asio::io_service when posting work on different thread?

我与影子孤独终老i 提交于 2019-12-25 02:54:00
问题 I'm trying to use a boost::lockfree queue to manage tasks. These tasks retrieve data and would be processed on a worker thread. Once data is retrieved, a signal should be sent to the main thread with the data. The worker thread is spawned at the start of the application and just keeps polling the queue. I'm new to Boost::Asio but from my research, it seems to be the best mechanism for sending signals between threads. I've looked at several examples, in particular: Confused when boost::asio:

Qt connect “no such slot” when slot exists [duplicate]

不羁的心 提交于 2019-12-24 16:27:17
问题 This question already has answers here : What does the Q_OBJECT macro do? Why do all Qt objects need this macro? (6 answers) Closed 5 years ago . I am trying to connect a signal to a slot. The project compiles fine, but at runtime I get this error: QObject::connect: No such slot QHeaderView::onFilterAdded(int) here is my code: class MySortFilterProxyModel: public QSortFilterProxyModel { Q_OBJECT public: explicit MySortFilterProxyModel(QObject *parent = 0); ~MySortFilterProxyModel(); void

How do I connect slot to user defined variable in Qt?

两盒软妹~` 提交于 2019-12-24 14:45:22
问题 Sorry if I'm missing something obvious, but I can't seem to find an answer to my question. Any help would be appreciated. I am trying to use a QSlider to manipulate data in a class I created. In the main window constructor I have the following: connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); With a slot defined in the same class: class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: