1

我正在尝试创建一个已创建的自定义项目向量,但遇到了一个非常奇怪的问题。

当我创建我的类的一个实例时,我没有任何问题,但是当我尝试添加它时,我有一个很长的错误,我不知道该怎么做。

我不知道它是否有帮助,但 m_mesureList 是 PanneauMesure 类的私有属性。

.h 中的声明:

std::vector<Mesure> m_mesureList;

采用:

void PanneauMesure::add(QPointF point1, QPointF point2, QPointF point3, QGraphicsItem *line1, QGraphicsItem *line2)
{
    Mesure mesure(point1, point2, point3, line1, line2, this);
    //m_mesureList.push_back(mesure);
}

错误:

In file included from ..\testQt\/PanneauMesure.h:21,
                 from ..\testQt\PanneauMesure.cpp:1:
d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h: In copy constructor 'Mesure::Mesure(const Mesure&)':
..\testQt\/Mesure.h:14:   instantiated from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = Mesure]'
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:737:   instantiated from 'void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = Mesure, _Alloc = std::allocator<Mesure>]'
..\testQt\PanneauMesure.cpp:104:   instantiated from here
d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h:806: error: 'QWidget::QWidget(const QWidget&)' is private
..\testQt\/Mesure.h:14: error: within this context
In file included from d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/mingw32/bits/c++allocator.h:34,
                 from d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/allocator.h:48,
                 from d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/string:43,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qstring.h:54,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qobject.h:48,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h:46,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/QWidget:1,
                 from ..\testQt\/PanneauMesure.h:4,
                 from ..\testQt\PanneauMesure.cpp:1:
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ext/new_allocator.h: In member function 'void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = Mesure]':
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ext/new_allocator.h:105: note: synthesized method 'Mesure::Mesure(const Mesure&)' first required here 
In file included from ..\testQt\/PanneauMesure.h:21,
                 from ..\testQt\PanneauMesure.cpp:1:
d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h: In member function 'Mesure& Mesure::operator=(const Mesure&)':
..\testQt\/Mesure.h:14:   instantiated from 'void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = Mesure, _Alloc = std::allocator<Mesure>]'
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:741:   instantiated from 'void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = Mesure, _Alloc = std::allocator<Mesure>]'
..\testQt\PanneauMesure.cpp:104:   instantiated from here
d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h:806: error: 'QWidget& QWidget::operator=(const QWidget&)' is private
..\testQt\/Mesure.h:14: error: within this context
In file included from d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/vector:69,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qvector.h:52,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtGui/qbrush.h:47,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtGui/qpalette.h:47,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h:49,
                 from d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/QWidget:1,
                 from ..\testQt\/PanneauMesure.h:4,
                 from ..\testQt\PanneauMesure.cpp:1:
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/vector.tcc: In member function 'void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = Mesure, _Alloc = std::allocator<Mesure>]':
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/vector.tcc:312: note: synthesized method 'Mesure& Mesure::operator=(const Mesure&)' first required here 

编辑,如果有帮助:

测量.cpp:

Mesure::Mesure(QPointF point1, QPointF point2, QPointF point3, QGraphicsItem *line1, QGraphicsItem *line2, QWidget *parent):
    QWidget(parent),
    m_hlayoutMesure(new QHBoxLayout(this)),
    m_buttonClose(new QToolButton(this)),
    m_labelAngle(new QLabel(this)),
    m_checkboxMesure(new QCheckBox(this)),
    m_point1(point1),
    m_point2(point2),
    m_point3(point3),
    m_line1(line1),
    m_line2(line2),
    m_angle(0)
{
    m_buttonClose->setText("X");
    m_labelAngle->setAlignment(Qt::AlignCenter);
    m_checkboxMesure->setChecked(true);
    m_hlayoutMesure->addWidget(m_checkboxMesure);
    m_hlayoutMesure->addWidget(m_labelAngle);
    m_hlayoutMesure->addWidget(m_buttonClose);
    m_hlayoutMesure->setSpacing(10);
    m_hlayoutMesure->setMargin(0);
    QObject::connect(m_buttonClose, SIGNAL(clicked()), this, SLOT(close()));
}

PanneauMesure.cpp:

PanneauMesure::PanneauMesure(QWidget *parent) :
    QWidget(parent),
    m_vlayoutTotal(new QVBoxLayout(this)),
    m_groupboxMesures(new QGroupBox("Mesures", this)),
    m_vlayoutGroupBoxMesures(new QVBoxLayout(m_groupboxMesures)),
    m_scrollareaMesures(new QScrollArea(m_groupboxMesures)),
    m_widgetMesures(new QWidget(m_groupboxMesures)),
    m_hlayoutMesures(new QHBoxLayout(m_widgetMesures)),
    m_vlayoutMesures(new QVBoxLayout(m_widgetMesures)),
    m_groupboxOptions(new QGroupBox("Options", this)),
    m_vlayoutOptions(new QVBoxLayout(m_groupboxOptions)),
    m_buttonRAZ(new QPushButton("Remise à zéro", m_groupboxOptions)),
    m_widgetAlpha(new QWidget(m_groupboxOptions)),
    m_hlayoutAlpha(new QHBoxLayout(m_widgetAlpha)),
    m_labelAlphaText(new QLabel("Alpha :", m_groupboxOptions)),
    m_labelAlphaValeur(new QLabel("50", m_groupboxOptions)),
    m_sliderAlpha(new QSlider(m_groupboxOptions)),
    m_hlayoutCouleur(new QHBoxLayout(m_groupboxOptions)),
    m_labelCouleur(new QLabel("Couleur :", m_groupboxOptions)),
    m_buttonCouleur(new QToolButton(m_groupboxOptions)),
    m_couleur(Qt::yellow),
    m_hlayoutLongueur(new QHBoxLayout(m_groupboxOptions)),
    m_labelLongueur(new QLabel("Longueur :  ", m_groupboxOptions)),
    m_spinboxLongueur(new QSpinBox(m_groupboxOptions)),
    m_longueur(20),
    m_hlayoutLargeur(new QHBoxLayout(m_groupboxOptions)),
    m_labelLargeur(new QLabel("Largeur :", m_groupboxOptions)),
    m_spinboxLargeur(new QSpinBox(m_groupboxOptions)),
    m_largeur(5),
    m_mesureList()
{
    // Alpha
    m_sliderAlpha->setMaximum(100);
    m_sliderAlpha->setValue(50);
    m_hlayoutAlpha->addWidget(m_labelAlphaText);
    m_hlayoutAlpha->addWidget(m_labelAlphaValeur);
    m_labelAlphaText->setAlignment(Qt::AlignRight);
    m_labelAlphaValeur->setAlignment(Qt::AlignLeft);
    m_sliderAlpha->setOrientation(Qt::Horizontal);
    QObject::connect(m_sliderAlpha, SIGNAL(valueChanged(int)), m_labelAlphaValeur, SLOT(setNum(int)));

    // Couleur
    QPixmap px(20, 20);
    px.fill(m_couleur);
    m_buttonCouleur->setIcon(px);
    m_hlayoutCouleur->addWidget(m_labelCouleur);
    m_hlayoutCouleur->addStretch(2);
    m_hlayoutCouleur->addWidget(m_buttonCouleur);
    m_hlayoutCouleur->addStretch(1);
    QObject::connect(m_buttonCouleur, SIGNAL(clicked()), this, SLOT(ouvrirCouleur()));

    // Longueur
    m_spinboxLongueur->setMinimum(1);
    m_spinboxLongueur->setValue(m_longueur);
    m_spinboxLongueur->setMaximum(999);
    m_hlayoutLongueur->addWidget(m_labelLongueur);
    m_hlayoutLongueur->addStretch(1);
    m_hlayoutLongueur->addWidget(m_spinboxLongueur);
    QObject::connect(m_spinboxLongueur, SIGNAL(valueChanged(int)), this, SLOT(sendParam()));

    // Largeur
    m_spinboxLargeur->setMinimum(1);
    m_spinboxLargeur->setMaximum(100);
    m_spinboxLargeur->setValue(m_largeur);
    m_hlayoutLargeur->addWidget(m_labelLargeur);
    m_hlayoutLargeur->addStretch(1);
    m_hlayoutLargeur->addWidget(m_spinboxLargeur);
    QObject::connect(m_spinboxLargeur, SIGNAL(valueChanged(int)), this, SLOT(sendParam()));

    // Options
    m_vlayoutOptions->addWidget(m_buttonRAZ);
    m_vlayoutOptions->addWidget(m_widgetAlpha);
    m_vlayoutOptions->addWidget(m_sliderAlpha);
    m_vlayoutOptions->addLayout((m_hlayoutCouleur));
    m_vlayoutOptions->addLayout((m_hlayoutLongueur));
    m_vlayoutOptions->addLayout((m_hlayoutLargeur));
    m_vlayoutOptions->setSpacing(0);
    QObject::connect(m_buttonRAZ, SIGNAL(clicked()), this, SLOT(remiseAZero()));

    // Mesures
    m_vlayoutMesures->addStretch(1);
    m_hlayoutMesures->addStretch(1);
    m_hlayoutMesures->addLayout(m_vlayoutMesures);
    m_hlayoutMesures->addStretch(1);
    m_widgetMesures->setLayout(m_hlayoutMesures);
    m_scrollareaMesures->setWidgetResizable(true);
    m_scrollareaMesures->setWidget(m_widgetMesures);
    m_scrollareaMesures->setFrameShape(QFrame::NoFrame);
    m_vlayoutGroupBoxMesures->addWidget(m_scrollareaMesures);
    m_vlayoutGroupBoxMesures->setMargin(0);

    // Total
    m_vlayoutTotal->addWidget(m_groupboxOptions);
    m_vlayoutTotal->addWidget(m_groupboxMesures);

}

void PanneauMesure::add(QPointF point1, QPointF point2, QPointF point3, QGraphicsItem *line1, QGraphicsItem *line2)
{
    Mesure mesure(point1, point2, point3, line1, line2, this);
    m_mesureList.push_back(mesure);
    //m_vlayoutMesures->insertWidget(0, &m_mesure);
    //QObject::connect(m_buttonRAZ, SIGNAL(clicked()), &m_mesure, SLOT(close()));
}

void PanneauMesure::remiseAZero()
{
    m_sliderAlpha->setValue(50);
    m_longueur = 20;
    m_spinboxLongueur->setValue(m_longueur);
    m_largeur = 5;
    m_spinboxLargeur->setValue(m_largeur);
    m_couleur = Qt::yellow;
    QPixmap px(20, 20);
    px.fill(m_couleur);
    m_buttonCouleur->setIcon(px);
    emit changementParam(m_couleur, m_longueur, m_largeur);
}

void PanneauMesure::ouvrirCouleur()
{
    QColor color = QColorDialog::getColor(m_couleur);
    if (color.isValid()) m_couleur=color;
    QPixmap px(20, 20);
    px.fill(m_couleur);
    m_buttonCouleur->setIcon(px);
    emit changementParam(m_couleur, m_longueur, m_largeur);
}

void PanneauMesure::sendParam()
{
    m_longueur = m_spinboxLongueur->value();
    m_largeur = m_spinboxLargeur->value();
    emit changementParam(m_couleur, m_longueur, m_largeur);
}
4

2 回答 2

6

从错误日志看来,它Mesure继承或包含一个QWidget不可复制的 。在 C++03 中,将类型放在序列中的要求是它们是可复制构造的,而您的类型不是。

于 2012-06-11T19:11:24.337 回答
2

正如 K-Ballo 指出的那样,你不能拥有一系列不可复制构造的元素,我只是存储了一系列指针,如下所示:

宣言:

std::vector<Mesure*> m_mesureList;

功能:

void PanneauMesure::add(QPointF point1, QPointF point2, QPointF point3, QGraphicsItem *line1, QGraphicsItem *line2)
{
    Mesure* mesure = new Mesure(point1, point2, point3, line1, line2, this);
    m_mesureList.push_back(mesure);
}
于 2012-06-11T19:27:16.000 回答