0

I am new to here.

The ui run well ,but when I click 'okbtn' ...

QObject::connect: No such slot QWidget::makeyourbox() in occQt.cpp:324

And when I click 'cancelbtn', it runs.

Thanks for any responses, Eason

code:

void occQt::about2()  //UI
{
    QWidget* pWidget = new QWidget;
    QLabel* longlabel = new QLabel(tr("long"));
    QLabel* widthlabel = new QLabel(tr("width"));
    QLabel* highlabel = new QLabel(tr("high"));
    longlineedit = new QLineEdit;
    widthlineedit = new QLineEdit;
    highlineedit = new QLineEdit;
    QPushButton* okbtn = new QPushButton(tr("ok"));
    QPushButton* cancelbtn = new QPushButton(tr("cancel"));
    QGridLayout* gridlayout = new QGridLayout;
    QVBoxLayout* dlglayout = new QVBoxLayout;
    QHBoxLayout* btnlayout = new QHBoxLayout;
    gridlayout->addWidget(longlabel, 0, 0, 1, 1);
    gridlayout->addWidget(widthlabel, 1, 0, 1, 1);
    gridlayout->addWidget(highlabel, 2, 0, 1, 1);
    gridlayout->addWidget(longlineedit, 0, 1, 1, 3);
    gridlayout->addWidget(widthlineedit, 1, 1, 1, 3);
    gridlayout->addWidget(highlineedit, 2, 1, 1, 3);
    longlineedit->setText("5");
    widthlineedit->setText("5");
    highlineedit->setText("5");
    btnlayout->setSpacing(60);
    btnlayout->addWidget(okbtn);
    btnlayout->addWidget(cancelbtn);
    //pWidget->setLayout(gridlayout);
    dlglayout->setMargin(50);
    dlglayout->addLayout(gridlayout);
    dlglayout->addStretch(40);
    dlglayout->addLayout(btnlayout);
    pWidget->setLayout(dlglayout);
    pWidget->setWindowTitle(tr("Make a Box by custom."));
    pWidget->show();
    connect(okbtn, SIGNAL(clicked()), pWidget, SLOT(makeyourbox()));
    //QObject::connect(okbtn, SIGNAL(clicked()), pWidget, SLOT(close()));
    connect(cancelbtn, SIGNAL(clicked()), pWidget, SLOT(close()));
}

void occQt::makeyourbox()
{
    QString string_a = longlineedit->text();
    eason_a = string_a.toInt();
    QString string_b = widthlineedit->text();
    eason_b = string_b.toInt();
    QString string_c = highlineedit->text();
    eason_c = string_c.toInt();
    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(eason_a, eason_b, eason_c).Shape();
    Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
    anAisBox->SetColor(Quantity_NOC_AZURE);
    mContext->Display(anAisBox);
}

When I run the pWidget, click cancelbtn, ui close. Click okbtn,do nothing..

eason
  • 171
  • 3
  • 18

3 Answers3

1

pWidget is a generic QWidget. It does not contain method/slot makeyourbox(). Your code is faulty.

dudeking
  • 764
  • 1
  • 9
  • 12
0

you should add makeyourbox() method to the subclass of QWidget, and mark it as slot

Tiko
  • 485
  • 4
  • 10
  • Thanks for your responses, but I don't think it should add... When adding it , I get the same result.. – eason May 17 '16 at 08:51
  • My English is poor so I need more time to respond to you,sorry. – eason May 17 '16 at 08:55
  • if occQt is subclass of QWidget, you should create an instance of it. This is not working beacause QWidget has no slot with name makeyourbox(). – Tiko May 17 '16 at 10:33
0

Double check makeyourbox is defined to be a slot within that class.

4pie0
  • 29,204
  • 9
  • 82
  • 118