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. Overloaded function type error
Forum Updated to NodeBB v4.3 + New Features

Overloaded function type error

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 5 Posters 7.6k Views 3 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.
  • J.HilkJ J.Hilk

    @gabor53 said in Overloaded function type error:

    if(newImage.open (QIODevice::ReadOnly)) {
    imageArray = newImage.readAll;
    }

    Hi,

    readAll is defined as a function
    QByteArray QIODevice::readAll()

    you're trying to access it, as if it were a member variable of QFile, which it is not

    imageArray = newImage.readAll();
    
    G Offline
    G Offline
    gabor53
    wrote on last edited by
    #3

    @J.Hilk
    I did what you recommended and it worked.
    I got a new error message saying
    C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:44: error: passing 'const QByteArray' as 'this' argument discards qualifiers [-fpermissive]
    imageArray = newImage.readAll();
    ^
    I believe everything is a const so it supposed to work, but it doesn't. Any idea what is still wrong?
    Thank you.

    artwawA 1 Reply Last reply
    0
    • G gabor53

      @J.Hilk
      I did what you recommended and it worked.
      I got a new error message saying
      C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:44: error: passing 'const QByteArray' as 'this' argument discards qualifiers [-fpermissive]
      imageArray = newImage.readAll();
      ^
      I believe everything is a const so it supposed to work, but it doesn't. Any idea what is still wrong?
      Thank you.

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #4

      @gabor53 remove const in const QByteArray imageArray; line in your header file...

      For more information please re-read.

      Kind Regards,
      Artur

      G 1 Reply Last reply
      1
      • artwawA artwaw

        @gabor53 remove const in const QByteArray imageArray; line in your header file...

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

        @artwaw
        In the .h file I have

        QByteArray imageArray;
        
          QString imageFile;
          void addNewImage(QString imageFile) const;
        
        

        and in the cpp file I have

        if(newImage.open (QIODevice::ReadOnly)) {
            imageArray = newImage.readAll();
          }
        
          QSqlQuery querys(db);
        
          if(!db.open ())
        
          {
            qDebug() << "The database is not open (submit)!";
          } else {
            qDebug() << "The database is open (submit)!";
          }
        //Get Id from somewhere
          querys.prepare("INSERT INTO Items (ID, Pic) VALUES(:ID, :Pic)" );
          querys.bindValue (":ID", sIDReview);
        }
        
        

        It still gives me the error message
        C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:44: error: passing 'const QByteArray' as 'this' argument discards qualifiers [-fpermissive]
        imageArray = newImage.readAll();
        ^

        Thank you for your help.

        artwawA 1 Reply Last reply
        0
        • G gabor53

          @artwaw
          In the .h file I have

          QByteArray imageArray;
          
            QString imageFile;
            void addNewImage(QString imageFile) const;
          
          

          and in the cpp file I have

          if(newImage.open (QIODevice::ReadOnly)) {
              imageArray = newImage.readAll();
            }
          
            QSqlQuery querys(db);
          
            if(!db.open ())
          
            {
              qDebug() << "The database is not open (submit)!";
            } else {
              qDebug() << "The database is open (submit)!";
            }
          //Get Id from somewhere
            querys.prepare("INSERT INTO Items (ID, Pic) VALUES(:ID, :Pic)" );
            querys.bindValue (":ID", sIDReview);
          }
          
          

          It still gives me the error message
          C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:44: error: passing 'const QByteArray' as 'this' argument discards qualifiers [-fpermissive]
          imageArray = newImage.readAll();
          ^

          Thank you for your help.

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #6

          @gabor53
          Why have you void addNewImage(QString imageFile) const;? Please try to remove const at the end.

          For more information please re-read.

          Kind Regards,
          Artur

          G 1 Reply Last reply
          1
          • artwawA artwaw

            @gabor53
            Why have you void addNewImage(QString imageFile) const;? Please try to remove const at the end.

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

            Artur,
            Now it gives a new error message:
            C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:30: error: passing 'const ImageDelegate' as 'this' argument discards qualifiers [-fpermissive]
            addNewImage (imageFile);
            ^

            My imagedelegate.h:

             void addNewImage(QString imageFile);
            

            the call in 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);
            }
            

            (this causes the error)

            and the function

            oid ImageDelegate::addNewImage(QString imageFile) {
              qDebug() << "Entered addNewImage";
            
              QFile newImage(imageFile);
            
              if(newImage.open (QIODevice::ReadOnly)) {
                imageArray = newImage.readAll();
              }
            
              QSqlQuery querys(db);
            
              if(!db.open ())
            
              {
                qDebug() << "The database is not open (submit)!";
              } else {
                qDebug() << "The database is open (submit)!";
              }
            //Get Id from somewhere
              querys.prepare("INSERT INTO Items (ID, Pic) VALUES(:ID, :Pic)" );
              querys.bindValue (":ID", sIDReview);
            }
            
            

            Thank you for your help.

            jsulmJ 1 Reply Last reply
            0
            • G gabor53

              Artur,
              Now it gives a new error message:
              C:\Programming\Projects\Folkfriends_bzr\trunk\imagedelegate.cpp:30: error: passing 'const ImageDelegate' as 'this' argument discards qualifiers [-fpermissive]
              addNewImage (imageFile);
              ^

              My imagedelegate.h:

               void addNewImage(QString imageFile);
              

              the call in 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);
              }
              

              (this causes the error)

              and the function

              oid ImageDelegate::addNewImage(QString imageFile) {
                qDebug() << "Entered addNewImage";
              
                QFile newImage(imageFile);
              
                if(newImage.open (QIODevice::ReadOnly)) {
                  imageArray = newImage.readAll();
                }
              
                QSqlQuery querys(db);
              
                if(!db.open ())
              
                {
                  qDebug() << "The database is not open (submit)!";
                } else {
                  qDebug() << "The database is open (submit)!";
                }
              //Get Id from somewhere
                querys.prepare("INSERT INTO Items (ID, Pic) VALUES(:ID, :Pic)" );
                querys.bindValue (":ID", sIDReview);
              }
              
              

              Thank you for your help.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @gabor53 Why is ImageDelegate::setModelData const?!
              Only methods which do not change the STATE of the object are allowed to be const.
              And you cannot call non const methods in const methods.
              So, remove the const from ImageDelegate::setModelData...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @jsulm In this case, setModelData should stay const, it's the original method signature. addNewImage should be made const (and its parameter a const reference). And also, why not use the model directly to store the new data ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                G 1 Reply Last reply
                0
                • SGaistS SGaist

                  @jsulm In this case, setModelData should stay const, it's the original method signature. addNewImage should be made const (and its parameter a const reference). And also, why not use the model directly to store the new data ?

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

                  @SGaist
                  Is there an example how to do it? I have 2 data types: image and text. If there is a way to let the model store the data and update the db instead of my delegate that would save a lot of coding.
                  Thank you.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    Can you give a more complete description of what you are trying to achieve ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    G 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Can you give a more complete description of what you are trying to achieve ?

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

                      @SGaist
                      This part displays the DB data in a table view where the user can review and correct data. Some of the fields are corrected as text fields, some of them as drop downs and I also have an image field. That's why I have the mydelegate and image delegate classes to handle the different editors. My struggle is to pass the image file name to a function where the corrected image can be saved to the DB replacing the old, incorrect image.
                      The problem is that the original delegate functions are const functions and as I most likely incorrectly handle them I keep getting different error messages.
                      Thank you for your help.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        Then there's no need for a "do-it-all" delegate.

                        Assign your delegate only to the column where it make sense. That will simplify your life.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        G 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Then there's no need for a "do-it-all" delegate.

                          Assign your delegate only to the column where it make sense. That will simplify your life.

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

                          @SGaist
                          Which is the better: to have a separate delegate for each column where needed or have one delegate for each type of input method ? (For example one delegate handles all dropdowns, one all check idea etc.)
                          Thank you.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            You only need as many delegate as you have special cases.

                            Note that I didn't say "as many as the column count". If you have several columns of a special type then juste instantiate one delegate per column.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            G 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              You only need as many delegate as you have special cases.

                              Note that I didn't say "as many as the column count". If you have several columns of a special type then juste instantiate one delegate per column.

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

                              @SGaist
                              How can I use the model directly to save the newly picked image? Is there a sample code you know about?

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                Well, you have a pointer to your model in setModelData, so why not use it ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                G 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  Well, you have a pointer to your model in setModelData, so why not use it ?

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

                                  @SGaist
                                  I started to use the pointer in setModelData. Added

                                  oid 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);
                                      //Adding image to db
                                  
                                      qDebug() << "Selected file: " << imgPick->selectedFile();
                                      qDebug() << "Selected file name: " << imgPick->m_selectedFile;
                                  //new
                                      model->setData (index, imgPick->selectedFile (), Qt::DecorationRole);
                                    }
                                  

                                  Causes no error, but doesn't save the img to the db ether. What am I supposed to use to commit the changes to the db?

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #19

                                    What kind of model are you using ?

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    G 1 Reply Last reply
                                    0
                                    • SGaistS SGaist

                                      What kind of model are you using ?

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

                                      @SGaist
                                      I use QStandardItemModel.

                                      #include "fixdb.h"
                                      #include "ui_fixdb.h"
                                      #include <QDebug>
                                      
                                      FixDb::FixDb(QWidget* parent) :
                                        QDialog(parent),
                                        ui(new Ui::FixDb) {
                                        ui->setupUi(this);
                                      
                                        correctFriend ();
                                      }
                                      
                                      FixDb::~FixDb() {
                                        delete ui;
                                      }
                                      
                                      void FixDb::correctFriend() {
                                        QSqlQuery query_fix ("SELECT * FROM Items ORDER BY name asc");
                                      
                                        if(query_fix.isActive () == true) {
                                          qDebug() << "The query_fix is active!";
                                        } else {
                                          qDebug() << "The query_fix is NOT active!" << query_fix.lastError ();
                                        }
                                      
                                        QStandardItemModel* fixModel = new QStandardItemModel(this);
                                        ui->tableView_Fix->setModel (fixModel);
                                      
                                      
                                        ui->tableView_Fix->setItemDelegateForColumn(3, new ImageDelegate(this));
                                      
                                      
                                        for(int row1 = 0; query_fix.next (); row1++) {
                                          if(row1 == 0) {
                                            const QSqlRecord qRec = query_fix.record();
                                            qDebug() << "The number of records (MainWindow): " << qRec;
                                            fixModel->insertColumns (0, qRec.count());
                                            qDebug() << "fixdb record count: " << qRec.count ();
                                      
                                          }
                                      
                                          fixModel->insertRow (row1);
                                          fixModel->setData (fixModel->index (row1, 0), query_fix.value (0));
                                          fixModel->setData (fixModel->index (row1, 1), query_fix.value (1));
                                          fixModel->setData (fixModel->index (row1, 2), query_fix.value (11));
                                      
                                          fixPixmap.loadFromData (query_fix.value (2).toByteArray ());
                                          fixPixmap = fixPixmap.scaled (100, 100, Qt::KeepAspectRatio);
                                      
                                          fixModel->setData (fixModel->index (row1, 3), fixPixmap, Qt::DecorationRole);
                                          fixModel->setData (fixModel->index (row1, 4), query_fix.value (11));
                                          fixModel->setData (fixModel->index (row1, 5), query_fix.value (10));
                                          fixModel->setData (fixModel->index (row1, 6), query_fix.value (3));
                                          fixModel->setData (fixModel->index(row1, 7), query_fix.value (4));
                                          fixModel->setData (fixModel->index (row1, 8), query_fix.value (12));
                                          fixModel->setData (fixModel->index (row1, 9), query_fix.value (7));
                                          fixModel->setData (fixModel->index (row1, 10), query_fix.value (8));
                                          fixModel->setData (fixModel->index (row1, 11), query_fix.value (9));
                                      
                                          ui->tableView_Fix->setRowHeight (row1, 100);
                                        }
                                      
                                        ui->tableView_Fix->horizontalHeader ()->setStyleSheet ("QHeaderView{font: 14pt Arial; color: blue; font-weight: bold; text-decoration: underline;}");
                                        ui->tableView_Fix->verticalHeader ()->setVisible (false);
                                        ui->tableView_Fix->setAlternatingRowColors (true);
                                        ui->tableView_Fix->setStyleSheet ("alternate-background-color: rgb(224,255,248); background-color: white; font: 14pt Arial; ");
                                      
                                        fixModel->setHeaderData (0, Qt::Horizontal, QObject::tr ("ID"));
                                        fixModel->setHeaderData (1, Qt::Horizontal, QObject::tr ("Name"));
                                        fixModel->setHeaderData (2, Qt::Horizontal, QObject::tr ("What"));
                                        fixModel->setHeaderData (3, Qt::Horizontal, QObject::tr ("Image"));
                                        fixModel->setHeaderData (4, Qt::Horizontal, QObject::tr ("Material"));
                                        fixModel->setHeaderData (5, Qt::Horizontal, QObject::tr ("Color"));
                                        fixModel->setHeaderData (6, Qt::Horizontal, QObject::tr ("Description"));
                                        fixModel->setHeaderData (7, Qt::Horizontal, QObject::tr ("Adoption Date"));
                                        fixModel->setHeaderData (8, Qt::Horizontal, QObject::tr ("Signed by"));
                                        fixModel->setHeaderData (9, Qt::Horizontal, QObject::tr ("History"));
                                        fixModel->setHeaderData (10, Qt::Horizontal, QObject::tr ("Age"));
                                        fixModel->setHeaderData (11, Qt::Horizontal, QObject::tr ("Notes"));
                                      
                                        ui->tableView_Fix->setColumnWidth (0, 60);
                                        ui->tableView_Fix->setColumnWidth (1, 120);
                                        ui->tableView_Fix->setColumnWidth (2, 150);
                                        ui->tableView_Fix->setColumnWidth (3, 100);
                                        ui->tableView_Fix->setColumnWidth (4, 130);
                                        ui->tableView_Fix->setColumnWidth (5, 120);
                                        ui->tableView_Fix->setColumnWidth (6, 400);
                                        ui->tableView_Fix->setColumnWidth (7, 150);
                                        ui->tableView_Fix->setColumnWidth (8, 200);
                                        ui->tableView_Fix->setColumnWidth (9, 400);
                                        ui->tableView_Fix->setColumnWidth (10, 130);
                                        ui->tableView_Fix->setColumnWidth (11, 300);
                                      
                                        ui->tableView_Fix->setWordWrap (true);
                                      
                                      
                                      }
                                      
                                      
                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #21

                                        Why not use a QSqlTableModel ?

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        G 1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          Why not use a QSqlTableModel ?

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

                                          @SGaist
                                          I had difficulties with the elegates. Can I still use different delegates for some columns? If so I will redo that section.

                                          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