Important: Please read the Qt Code of Conduct -

Error message when calling function

  • Hi,
    I have the addNewImage function with the following code:

     void addNewImage(QString imageFile);


    void ImageDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
      ImagePickButton* imgPick = qobject_cast<ImagePickButton*>(editor);
      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 {
    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 function setModelData. So you have to remove const from setModelData or add const to addNewImage.


  • @m.sue
    Thank you. It worked.

Log in to reply