Question

I need some help with connection of signal and slot. this is what i have.

In .h file area is the examplar of the class which inherited from QMdiArea. AddSubWindow is slot of this class, and it works correct with other signal. compiler said

"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()
{

}

slot

void MyMdiArea::AddSubWindow(bool i)
{
    //QString str="заголовок";
    MyWindow *widget = new MyWindow(0,str1);

    addSubWindow(widget);
    widget->setWindowTitle(str1);
    widget->show();


}

h. file

#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
Was it helpful?

Solution

The problem is:

Signal clicked() has no parameter, but slot AddSubWindow() has a parameter of bool type. That's not allowed in Qt.

OTHER TIPS

try change your code like this

.h

public slots:
void AddSubWindow();

.cpp

void MyMdiArea::AddSubWindow()
{
QString str="заголовок";
MyWindow *widget = new MyWindow(0,str1);

addSubWindow(widget);
widget->setWindowTitle(str1);
widget->show();


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top