简体   繁体   English

将QGraphicsview信号连接到UI插槽

[英]connecting QGraphicsview signal to UI slot

I am new to QT and C++ and i have legacy qt-c++ code here which i cant get to work. 我是QT和C ++的新手,我在这里有遗留的qt-c ++代码,无法正常工作。 Probably its something about the lifetime of the calling objects but hey, but please tell me what i am missing. 可能与调用对象的生命周期有关,但是,但是,请告诉我我所缺少的内容。

In a QT .ui i have various Frames and Widgets containing Frames and Widgets containing a QVBoxLayout which we shall call "myLayout" 在QT .ui中,我有各种框架和小部件,其中包含框架和小部件,其中包含QVBoxLayout ,我们将其称为“ myLayout”

On click in the .ui file i use 在我使用的.ui文件中单击

myWidget = new mywidget(some params);
myLayout->addWidget(myWidget);

where myWidget is declared as mywidget *myWidget; 其中myWidget被声明为mywidget *myWidget; in the header file 在头文件中

myWidget is a QWidget which internally adds a QVBoxLayout to itself and adds a QGraphicsView . myWidget是一个QWidget ,它在内部QVBoxLayout自身添加QVBoxLayout并添加QGraphicsView Using the MouseReleaseEvent i emit a signal from the QWidget. 使用MouseReleaseEvent我从QWidget发出信号。

now when i try to connect the signal slot (which i do in cpp file from the ui) 现在,当我尝试连接信号插槽时(我在ui的cpp文件中执行此操作)

connect(myWidget, SIGNAL(mySignal(QString)), this, SLOT(mySlot(QString)));

the signals never catch the slot. 信号永远不会卡住插槽。 the slot is public, the signal isnt. 插槽是公共的,信号不是。

What did i do wrong? 我做错了什么? Can somebody help. 有人可以帮忙吗? Feel free to ask further questions since i dont really know whats important in c++ questions;) 随意提出其他问题,因为我真的不知道在C ++问题中什么重要;)

edit: the signal gets emitted by QGraphicsObjects which themselfs connect to a slot in the QGraphicsView . 编辑:信号得到由发射QGraphicsObjects其中themselfs连接到在狭槽QGraphicsView This Slot is called and debuggable. 该插槽称为可调试插槽。 at the end of the Routine an emit mySignal("..."); 在例程结束时, emit mySignal("..."); is called. 叫做。

Maybe you forgot to add Q_OBJECT macro in your widget declaration. 也许您忘记在小部件声明中添加Q_OBJECT宏。 Qt documentation: http://doc.qt.io/qt-5/qobject.html#Q_OBJECT Qt文档: http : //doc.qt.io/qt-5/qobject.html#Q_OBJECT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM