0

我是新来的。

用户界面运行良好,但是当我单击“okbtn”时...

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

当我单击“取消”时,它会运行。

感谢您的任何回复,Eason

代码:

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);
}

当我运行 pWidget 时,单击 cancelbtn,ui 关闭。点击okbtn,什么都不做。。

4

3 回答 3

1

pWidget 是一个通用的 QWidget。它不包含方法/槽 makeyourbox()。你的代码有问题。

于 2016-05-18T10:08:02.407 回答
0

您应该将makeyourbox()方法添加到 的子类QWidget,并将其标记为插槽

于 2016-05-17T08:34:08.843 回答
0

双重检查makeyourbox被定义为该类中的一个插槽。

于 2016-05-17T08:51:28.537 回答