2016-05-17 32 views
0

我是新來的。QObject :: connect:沒有這樣的插槽QWidget :: makeyourbox()在occQt.cpp中:324

運行良好的用戶界面,但是當我點擊 'okbtn' ......

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

,當我點擊 'cancelbtn',它運行。

感謝您的任何答覆, 陳奕迅

代碼:

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,什麼都不做..

+0

請格式化您的代碼 – paceholder

+0

http://stackoverflow.com/q/26422154/1421332 – Silicomancer

+0

謝謝你,它解決了。 – eason

回答

1

pWidget是一個通用的QWidget。它不包含method/slot makeyourbox()。 您的代碼有問題。

+0

哦...謝謝。我想我會得到道路。 – eason

0

你應該添加makeyourbox()方法的QWidget子類,並將其標記爲槽

+0

感謝您的回覆,但我認爲它不應該添加... 添加它時,我得到相同的結果。 – eason

+0

這樣做的業務嗎? – Tiko

+0

我的英語很差,所以我需要更多時間回覆你,抱歉。 – eason

0

仔細檢查makeyourbox被定義爲是類中的一個插槽。

相關問題