Qt:在 2 个不同的窗口中将 SIGNAL 连接到 SLOT
我要发疯了,试图找到这里的问题。我有一个主窗口和一个用 Qt 制作的表单类型窗口。我正在使用 Visual Studio 2010 插件。由于某种原因,我的 SLOT 从未在主窗口中调用;然而,信号似乎已发出。
这是我所做的:
这是形式:
class ScalerValuesWindow : public QWidget
{
Q_OBJECT
private:
Ui::ScalerValuesWindow ui;
// Variables
std::vector<int> scalerValues;
public slots:
void storeScalerValues();
signals:
void ScalerValues(std::vector<int>);
public:
ScalerValuesWindow(QWidget *parent = 0);
};
void ScalerValuesWindow::storeScalerValues()
{
emit ScalerValues(scalerValues);
hide();
}
然后这是我的构造函数中的主窗口连接行:
scalerValuesWindow = new ScalerValuesWindow;
connect(scalerValuesWindow, SIGNAL(ScalerValues(std::vector<int>)), this, SLOT(RetrieveScalerValues(std::vector<int>)));
这是在我的主窗口的类声明中:
public slots:
void RetrieveScalerValues(vector<int> scalerValues);
这是槽:
void RelayduinoGuiThreading::RetrieveScalerValues(vector<int> scalerVals)
{
scalerValues = scalerVals;
}
我在两者中都声明了 Q_OBJECT。我不知道是什么原因造成的。
任何建议将不胜感激。
I'm going nuts trying to find the problem here. I have a main window, and a form type window made in Qt. I'm using the Visual Studio 2010 addon. For some reason, my SLOT is never called in the main window; however, the signal appears to be emitted.
Here's what I've done:
This is the form:
class ScalerValuesWindow : public QWidget
{
Q_OBJECT
private:
Ui::ScalerValuesWindow ui;
// Variables
std::vector<int> scalerValues;
public slots:
void storeScalerValues();
signals:
void ScalerValues(std::vector<int>);
public:
ScalerValuesWindow(QWidget *parent = 0);
};
void ScalerValuesWindow::storeScalerValues()
{
emit ScalerValues(scalerValues);
hide();
}
Then here's my main window connection line in my constructor:
scalerValuesWindow = new ScalerValuesWindow;
connect(scalerValuesWindow, SIGNAL(ScalerValues(std::vector<int>)), this, SLOT(RetrieveScalerValues(std::vector<int>)));
This is in my main window's class declaration:
public slots:
void RetrieveScalerValues(vector<int> scalerValues);
And this is the slot:
void RelayduinoGuiThreading::RetrieveScalerValues(vector<int> scalerVals)
{
scalerValues = scalerVals;
}
I have Q_OBJECT declared in both. I have no idea what could be causing this.
Any advice would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将插槽定义为:(
检查生成的
moc
文件以准确查看正在生成的信号/插槽签名。)请勿在您的标头,无论如何,这都是不好的做法(将巨大的名称空间拉入该标头的所有用户中,这是不礼貌的)。
You must define your slot as:
(Inspect the generated
moc
file to see exactly what signal/slot signatures are being generated.)Don't use
using namespace std;
in your headers, that's bad practice anyway (pulls in that huge namespace into all the users of that header, which is impolite).