signals-slots

Is this method of inter-thread-communication safe?

China☆狼群 提交于 2019-12-05 15:59:53
I have 3 objects(inherited from QObject ) that each contain a separate std::list . Each object gets created in the main gui thread (with no parent) and then is pushed to it's own thread (using Qt's QObject::moveToThread() ). Each thread is hooked up to a gui and messages are sent between the different threads with data. Each thread is to essentially handle it's own list. For example: Obj 1 : Consumer of data. It pop's the front off of its list(if data is present) to use. It also has a SLOT available so that other threads can push data to it. No other object can access this list directly only

Keeping the GUI separate

巧了我就是萌 提交于 2019-12-05 15:47:33
I have a program that (amongst other things) has a command line interface that lets the user enter strings, which will then be sent over the network. The problem is that I'm not sure how to connect the events, which are generated deep inside the GUI, to the network interface. Suppose for instance that my GUI class hierarchy looks like this: GUI -> MainWindow -> CommandLineInterface -> EntryField Each GUI object holds some other GUI objects and everything is private. Now the entryField object generates an event/signal that a message has been entered. At the moment I'm passing the signal up the

How to pass variables to slot methods in QT?

只愿长相守 提交于 2019-12-05 15:17:23
问题 I'm making a little chat messenger program, which needs a list of chat channels the user has joined. To represent this list graphically, I have made a list of QPushButtons , which all represent a different channel. These buttons are made with the following method, and that's where my problem kicks in: void Messenger::addToActivePanels(std::string& channel) { activePanelsContents = this->findChild<QWidget *>(QString("activePanelsContents")); pushButton = new QPushButton(activePanelsContents);

Qt QLabel click event

放肆的年华 提交于 2019-12-05 11:33:58
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 ?! 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_QLabel If you choose the latter option you can pass the text in the signal. Then connect the necessary signals

Qt connect “no such slot” when slot definitely does exist

孤街醉人 提交于 2019-12-05 10:27:49
Qt v4.8.0, VC2010 compiler I have a QMainWindow based class and I'm trying to send it signals involving QUuid However, every time I run it I get the errors: Object::connect: No such slot MainWindow::on_comp_connected(QUuid) in ..\..\src\mainwindow.cpp:143 Object::connect: (receiver name: 'MainWindow') It's driving me potty as the slot definitely does exist (it's in the moc_) class MainWindow : public QMainWindow { Q_OBJECT // SNIP private typedefs public: MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); ~MainWindow(); // SNIP public methods signals: void testSendQuuid(const QUuid &qcid);

Resolving conflicts with PyQt new-style signals-slots

元气小坏坏 提交于 2019-12-05 10:23:40
QComboBox has two signals, both called currentIndexChanged ; one passes the index of the selected item, and the other passes the text of the selected item. When I connect this signal to my slot, with something like self.myComboBox.currentIndexChanged.connect(self.mySlot) it gives me an index. Is there a way I can use new-style signals to indicate that I want the text returned? Avaris See the second example in connecting signals portion of documentation. In your case it would be: self.myComboBox.currentIndexChanged[QtCore.QString].connect(self.mySlot) or if you are using v2 API for QString self

How to bind to a signal from a delegate component within a ListView in QML

心不动则不痛 提交于 2019-12-05 05:43:28
Let's say I have a ListView of clickable delegate components (or GridView or Repeater ). These delegate components need to emit a signal along with custom data when triggered that can be picked up by the parent of the ListView . How can this signal binding be achieved? e.g. The following code is my attempt but I don't know how to bind the trigger signal of the delegate component to the componentTriggered signal in the root item? Item { id: root anchors.fill: parent signal componentTriggered(string name) onComponentTriggered: { console.log(name + ' component was triggered') } ListModel { id:

Qt GUI app: warning if QObject::connect() failed?

半城伤御伤魂 提交于 2019-12-05 01:34:21
I recently migrated my Qt project from Linux to Vista, and now I'm debugging signals blindly. On Linux, if QObject::connect() fails in a debug build, I get a warning message on stderr. On Windows, there is no console output for GUI applications, only an OutputDebugString call. I already installed DebugView , and it catches my own qDebug() output nicely, but still no warning on failed signals. One possible solution would be to use QtCreator's autocomplete for signals, but I like Eclipse, and using both is a PITA. Any ideas on how to get signal/slot info at runtime? Edit: I just realized connect

Signals vs Signals2

强颜欢笑 提交于 2019-12-05 00:07:01
I have application that may benefit from using one of boost's signals libraries over a homegrown solution. The application is multithreaded but the part that does the signal processing is single threaded. Is there any reason to prefer Boost.Signals2 over Boost.Signal if multithreading is not an issue? Boost.Signals is now deprecated, and Boost.Signals2 should be used instead (see v1.54 docs ) Originally, if all the signals and slots were in the same thread, boost.signals was just fine. However, it is no longer being maintained -- the documentation suggests using signals2 in all new code. 来源:

Emit signal in standard python thread

混江龙づ霸主 提交于 2019-12-04 23:16:50
问题 I have a threaded application where I do have a network thread. The UI-part passes a callback to this thread. The thread is a normal python thread - it's NO QThread . Is it possible to emit PyQT Slot within this thread? 回答1: No, it is not possible to emit a PyQt signal from a python thread like this. However, a possible solution is to use an additional object shared by both threads, making the necessary operations to finally emit a thread-safe PyQt signal. Here is an implementation of a