我需要一些信号和插槽连接的帮助。这就是我所拥有的。
在.h文件区域是继承自QMdiArea的类的示例。 AddSubWindow是这个类的插槽,它与其他信号一起工作正常。编译说
"QObject::connect: No such slot MyMdiArea::AddSubWindow(true) in workspace.cpp:37"
#include "workspace.h"
WorkSpace::WorkSpace(QWidget *parent)
: QWidget(parent)
{
HLayout=new QHBoxLayout;
VLayout=new QVBoxLayout;
TabButton = new QPushButton("Tabbed View");
SimpleButton = new QPushButton("Simple View");
AddButton = new QPushButton("Add Window");
HLayout->addWidget(AddButton);
HLayout->addWidget(TabButton);
HLayout->addWidget(SimpleButton);
str="Title";
area = new MyMdiArea(0,str);
area->setViewMode(QMdiArea::TabbedView);
area->setTabsClosable(true);
area->setTabsMovable(true);
VLayout->addLayout(HLayout);
VLayout->addWidget(area);
connect(AddButton,SIGNAL(clicked()),area,SLOT(AddSubWindow(true)));
this->setLayout(VLayout);
//this->show();
}
WorkSpace::~WorkSpace()
{
}
槽
void MyMdiArea::AddSubWindow(bool i)
{
//QString str="заголовок";
MyWindow *widget = new MyWindow(0,str1);
addSubWindow(widget);
widget->setWindowTitle(str1);
widget->show();
}
小时。档案
#include <QtWidgets/QMainWindow>
#include "ui_workspace.h"
#include "MyMdiArea.h"
#include "mywindow.h"
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTextBlock>
#include <qstring.h>
class WorkSpace : public QWidget
{
Q_OBJECT
public:
WorkSpace(QWidget *parent = 0);
~WorkSpace();
QHBoxLayout *HLayout;
QVBoxLayout *VLayout;
QPushButton *TabButton;
QPushButton *SimpleButton;
QPushButton *AddButton;
MyMdiArea *area;
QString str;
private:
Ui::WorkSpaceClass ui;
};
MyMdiArea.h
#ifndef MYMDIAREA_H
#define MYMDIAREA_H
#include <QWidget>
#include <QMdiArea>
#include <qmessagebox.h>
#include <qpixmap.h>
#include <qpainter.h>
#include "ui_mymdiarea.h"
class MyMdiArea : public QMdiArea
{
Q_OBJECT
public:
QString str1;
void SendSignal();
MyMdiArea(QWidget *parent,QString str);
~MyMdiArea();
void mouseDoubleClickEvent(QMouseEvent *event);
public slots:
void AddSubWindow(bool t);
signals:
void doubleClicked(bool t);
private:
Ui::MyMdiArea ui;
QPixmap logo;
protected:
void paintEvent(QPaintEvent *event);
};
#endif // MYMDIAREA_H
答案 0 :(得分:1)
问题是:
Signal clicked()
没有参数,但插槽AddSubWindow()
的参数为bool类型。 Qt中允许不。
答案 1 :(得分:1)
尝试像这样更改你的代码
·H
public slots:
void AddSubWindow();
的.cpp
void MyMdiArea::AddSubWindow()
{
QString str="заголовок";
MyWindow *widget = new MyWindow(0,str1);
addSubWindow(widget);
widget->setWindowTitle(str1);
widget->show();
}