gpt4 book ai didi

c++ - 按钮连接 Qt 失败

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:47:07 26 4
gpt4 key购买 nike

我需要一些关于信号和插槽连接的帮助。这就是我所拥有的。

.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

最佳答案

问题是:

Signal clicked()没有参数,但是slot AddSubWindow()有一个bool类型的参数。这在 Qt 中不允许

关于c++ - 按钮连接 Qt 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20604498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com