Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't store a QPointer into a QVariant
Qt 6.11 is out! See what's new in the release blog

Can't store a QPointer into a QVariant

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 6.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello,

    I'm trying to store a Pointer to a QVector<Album*> into a QAction, but I can't convert it to QVariant.

    I have
    @
    QVector<Album*>* data;
    action->setData(QVariant::fromValue(QPointer<QVector<Album*> >(data)));
    @

    and it fails with following error:

    In instantiation of 'QPointer<T>::QPointer(T*) [with T = QVectorDigikam::Album*]':
    /media/LinuxHDD/slavik/digikam-software-compilation/core/digikam/tags/tagmodificationhelper.cpp:98:72: required from here
    /usr/include/qt4/QtCore/qpointer.h:59:32: error: cannot convert 'QVectorDigikam::Album*' to 'QObject' in initialization
    inline QPointer(T *p) : o(p)

    I don't know how to deal with this... QPointer<QVector> works fine , but QPointer<QVector<Album*> > won't...

    Thank you!

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

      Hi,

      QPointer must be used with QObject, have a look at "this":http://qt-project.org/doc/qt-4.8/qpointer.html#details

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

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        But, QVector is a QObject, I only added a template argument to it...

        I can't use QPointer<QVector>(data) because of template mismatch.

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

          No, QVector is not a QObject, it's a templated container (you can verify in the source code).

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

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            QVector does not subclass QObject, so it is not a QObject.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              So a container won't work...

              Any idea of how to pass that pointer through QAction?

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

                You can use quintptr but are you sure that having that in the action is the best design ?

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

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  I was able to pass it with:

                  Q_DECLARE_METACALL(QList<Album*>)

                  Basically, I try to implement item deletion in a context menu. Originally, tree was single selection and a pointer to item was encoded into QAction's data. Now, I'm trying to implement multiple selection and deletion is the first one to change...

                  The design of KDE's digiKam is complicated and I can't have direct access to treeView to ask for selected items. Instead, I should stick to this design, but I accept all suggestions :)

                  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
                  • Unsolved