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. Signal issues in QStyledItemDelegate
Forum Updated to NodeBB v4.3 + New Features

Signal issues in QStyledItemDelegate

Scheduled Pinned Locked Moved General and Desktop
18 Posts 6 Posters 4.0k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by gabor53
    #9

    I changed the connect like this:

                QByteArray fixFile;
                connect(button,&QPushButton::clicked, [=] ()
                {
                     fixFile = getNewPix ();
                });
    

    I get a message immediately saying "member function getNewPix not viable: 'this' argument has type 'const myDelegate' but function is not marked const.

    getNewPix looks like this:

    const QByteArray myDelegate::getNewPix()
    {
        qDebug() << "Entered getNewPix!";
        QString sPath = "C:/";
    
    //    fileDialog = getOpenFileName (Q_NULLPTR,sPath);
    
        fileName = QFileDialog::getOpenFileName(Q_NULLPTR,
                                                tr("Finding Friend's replacement Image"),sPath, tr("Image Files (*.png *.jpg *.bmp)"));
    
    
        if(fileName == "")
            {
                qDebug() << "No image was chosen.";
    //            QMessageBox::warning (this,"Error 1039","No image was choosen!");
            }
        else
            {
                qDebug() << "Image was chosen!";
            }
    
        QFile file(fileName);
        if(file.open (QIODevice::ReadOnly))
            {
                qDebug() << "File  is open!";
                fixByteArray = file.readAll (); //QByteArray
                qDebug() << "Delegate file size: " << fixByteArray.size ();
    
            }
        else
            {
                qDebug() << "File is not open!";
            }
        return fixByteArray;
    }
    

    What should I change in this connect (or function) to make this work?
    Thank you.

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

      Hi,

      AFAICS your getNewPix function doesn't modify anything in your myDelegate class so you can either make it static or const. Static might make more sense since you also don't depend on anything from this class.

      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

        Hi,

        AFAICS your getNewPix function doesn't modify anything in your myDelegate class so you can either make it static or const. Static might make more sense since you also don't depend on anything from this class.

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

        @SGaist
        How can I make it static or or const? I tried to follow the instructions but I ended up with the same error message.

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

          What did you modify in your code ?

          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 did you modify in your code ?

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

            @SGaist
            Under setEditorData I have the following:

                QPushButton *button = qobject_cast<QPushButton*>(editor);
                if(button)
                    {
                        button->setStyleSheet ("background-color: rgba(255, 255, 255, 0);");
            
                        QByteArray fixFile;
                        connect(button,&QPushButton::clicked, [=] ()
                        {
                            fixByteArray =  getNewPix ();
                        }); 
            
                        qDebug() << "fixFileName: " << fixFile;
            
                        QPixmap retPix;
                        qDebug() << "case 3 bytearray size: " << fixByteArray.size ();
            
                        if((retPix.loadFromData (fixByteArray)) == true)
                            {
                                qDebug() << "retPix loaded!";
                                qDebug() << "retPix sizse: " << retPix.size ();
                            }
                        else
                            {
                                qDebug() << "retPix is NOT loaded!";
                            }
                        return;
                    }
            

            getNewPix() looks like this:

            QByteArray myDelegate::getNewPix()
            {
                {
                    qDebug() << "Entered getNewPix!";
                    QString sPath = "C:/";
            
                    //    fileDialog = getOpenFileName (Q_NULLPTR,sPath);
            
            
                    const QString fileName = QFileDialog::getOpenFileName(Q_NULLPTR,
                                             tr("Finding Friend's replacement Image"),sPath, tr("Image Files (*.png *.jpg *.bmp)"));
            
            
                    if(fileName == "")
                        {
                            qDebug() << "No image was chosen.";
                        }
                    else
                        {
                            qDebug() << "Image was chosen!";
                        }
            
                    QFile file(fileName);
                    if(file.open (QIODevice::ReadOnly))
                        {
                            qDebug() << "File  is open!";
            
                            fixByteArray = file.readAll ();
            
                            qDebug() << "Delegate file size: " << fixByteArray.size ();
                            return fixByteArray;
            
                        }
                    else
                        {
                            qDebug() << "File is not open!";
                        }
                    return fixByteArray;
                }
            
            };
            
            

            I get 2 error messages:
            1st at the fixByteArray = getNewPix (); line:
            C:\Programming\Projects\Folkfriends_1_0\mydelegate.cpp:188: error: passing 'const myDelegate' as 'this' argument discards qualifiers [-fpermissive]
            fixByteArray = getNewPix ();
            ^
            2nd at fixByteArray = file.readAll (); is technically the same error:
            C:\Programming\Projects\Folkfriends_1_0\mydelegate.cpp:572: error: passing 'const QByteArray' as 'this' argument discards qualifiers [-fpermissive]
            fixByteArray = file.readAll ();
            ^
            Thank you.

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

              Looks like fixByteArray is a class member which is not needed following your function implementation.

              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

                Looks like fixByteArray is a class member which is not needed following your function implementation.

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

                @SGaist
                Is there any other way I can load the file into fixByteArray?

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #16

                  Since you are having issues with this it's probably faster and safer to implement it in the right way.

                  Build whatever you want your editor delegate to be as a QWidget subclass and then create it inside the createEditor method of your delegate.

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

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

                    Make fixByteArray local since you return its content from the function.

                    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

                      Make fixByteArray local since you return its content from the function.

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

                      @SGaist
                      Under setEditorData I created the following code that actually works:

                        QPushButton *button = qobject_cast<QPushButton*>(editor);
                      
                          if(button)
                              {
                                  connect(button,&QPushButton::clicked, [=] ()
                                  {
                                      qDebug() << "Entered getNewPix!";
                                      QString sPath = "C:/";
                                      const QString fileName = QFileDialog::getOpenFileName(Q_NULLPTR,
                                                               tr("Finding Friend's replacement Image"),sPath, tr("Image Files (*.png *.jpg *.bmp)"));
                      
                                      qDebug() << "fileName in setEditorData: " << fileName; //this works
                      
                                      if(fileName == "")
                                          {
                                              qDebug()    << "No image was chosen.";
                                          }
                      
                                      QFile file(fileName);
                                      if(file.open (QIODevice::ReadOnly))
                                          {
                                              qDebug()   << "File is open!";
                      
                                              QPixmap pix2;
                                              if(pix2.load (fileName) == true)
                                                  {
                                                      qDebug() << "Pixmap is loaded.";
                                                  }
                                          }
                                  });
                      
                                  return ;
                              }
                      

                      The issue is that I need pix2 in setModelData. Here it is declared in the if loop and works without any issues but I can't use it anywhere else. But if I declare it outside of the loop I keep getting the following error message:

                      C:\Programming\Projects\Folkfriends_1_0\mydelegate.cpp:152: error: passing 'const QPixmap' as 'this' argument discards qualifiers [-fpermissive]
                      if(pix2.load (fileName) == true)

                      How can I avoid this error?
                      Thank you.

                      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