Solved Error message when calling function
-
Hi,
I have the addNewImage function with the following code:
imagedelegate.h:void addNewImage(QString imageFile);
imagedelegate.cpp:
void ImageDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { ImagePickButton* imgPick = qobject_cast<ImagePickButton*>(editor); Q_ASSERT(imgPick); if(imgPick->selectedFile().isEmpty()) { model->setData(index, QVariant(), Qt::UserRole); model->setData(index, QVariant(), Qt::DecorationRole); } else { model->setData(index, imgPick->selectedFile(), Qt::UserRole); model->setData(index, QIcon(imgPick->selectedFile()), Qt::DecorationRole); addNewImage (imageFile);//Not working } } void ImageDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_UNUSED(index); editor->setGeometry(option.rect); } void ImageDelegate::addNewImage(QString imageFile) { qDebug() << "Entered addNewImage"; }
It gives me the following error message:
C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:30: error: passing 'const ImageDelegate' as 'this' argument discards qualifiers [-fpermissive]
addNewImage (imageFile);//Not working
^
What is incorrect?
Thank you for your help. -
Hi @gabor53
you cannot call the non-const function
addNewImage
in the const functionsetModelData
. So you have to remove const fromsetModelData
or add const toaddNewImage
.-Michael.
-
@m.sue
Thank you. It worked.