我正在修改现有程序。我在课堂上.h文件:
boost::scoped_ptr<QWidget> _widget;
我的.cpp文件中有一个方法:
void FaceRecoWidget::createWidget()
{
_widget.reset(new QDialog);
QVBoxLayout* layout(new QVBoxLayout);
// some stuff...
// Now I want to add a 'Cancel' button. This I what I do:
QPushButton* cancel_button(new QPushButton("Cancel"));
// but next line won't compile because _widget is not a 'const QObject*'
connect(cancel_button, SIGNAL(clicked()), _widget, SLOT(reject()));
layout->addWidget(cancel_button);
_widget->setLayout(layout);
}
我该如何解决这个问题?
答案 0 :(得分:2)
connect
接受指针,因此您应该传递存储在boost::scoped_ptr
中的原始指针:
connect(cancel_button, SIGNAL(clicked()), _widget.get(), SLOT(reject()));