Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error message when calling function
Forum Updated to NodeBB v4.3 + New Features

Error message when calling function

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 633 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    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.

    m.sueM 1 Reply Last reply
    0
    • G gabor53

      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.

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      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.

      -Michael.

      G 1 Reply Last reply
      2
      • m.sueM m.sue

        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.

        -Michael.

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @m.sue
        Thank you. It worked.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved