【发布时间】:2018-06-09 22:39:17
【问题描述】:
我正在尝试构建一个将 (qt) 类型作为参数并使用它来查找子级的函数。我的函数如下所示:
template <typename QType>
void MyClass::activateElements(QWidget *widget, QType t)
{
QList<QType *> buttons = widget->findChildren(t);
foreach( QType *button, buttons )
{
buttons->setEnabled(true);
}
}
我也试过
template <typename QType>
void MyClass::activateElements(QWidget *widget, QType)
{
QList<QType *> buttons = (* widget).findChildren<QType *>();
foreach( QType *button, buttons )
{
button->setEnabled(true);
}
}
我在另一个类中实例化了一个使用该函数的类的对象。在那里我尝试像这样使用它:
QDoubleSpinBox x;
object_of_my_class->activateElements(correctWidget, x);
此时我卡住了,因为我收到以下错误:
error: ‘QDoubleSpinBox::QDoubleSpinBox(const QDoubleSpinBox&)’ is private
Q_DISABLE_COPY(QDoubleSpinBox)
我将如何处理这个问题,QDoubleSpinBox 和其他人是私有的?我是否接近过如何错误地构建功能,或者我只是使用不正确?有没有办法做到这一点?
【问题讨论】:
-
"我将如何处理这个问题,QDoubleSpinBox 和其他人是私有的?" 错误指出
QDoubleSpinBox的 copy-constructor 是私人(即不能复制)。按引用传递而不是按值传递。
标签: c++ qt templates types qt4