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: reference to type 'NBhistoryItem *const' could not bind to an lvalue of type 'const NBhistoryItem *'
Forum Updated to NodeBB v4.3 + New Features

Error: reference to type 'NBhistoryItem *const' could not bind to an lvalue of type 'const NBhistoryItem *'

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.9k 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.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hello,

    I am getting this error:
    error: reference to type 'NBhistoryItem *const' could not bind to an lvalue of type 'const NBhistoryItem *'

    whenever the following code is called:
    void NBhistoryInterface::addHistoryItem(const NBhistoryItem *input)
    @
    {
    qDebug() << "SLOT: NBhistoryInterface::addHistoryItem(const NBhistoryItem &input) STATUS: Called";
    m_history.prepend(input);
    qDebug() << "SLOT: NBhistoryInterface::addHistoryItem(const NBhistoryItem &input) STATUS: Completed";
    }
    @

    m_history is a QList<NBhistoryItem*>

    What am I doing wrong?

    Thanks!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Your list is of pointers to non-const NBhistoryItems and you are trying to prepend a pointer to a const NBhistoryItem.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nicky j
        wrote on last edited by
        #3

        okay, so then what should it look like?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          Either this (if the NBhistoryItems should be modifiable through the pointers in the list):
          @
          QList<NBhistoryItem*> m_list;

          void NBhistoryInterface::addHistoryItem(NBhistoryItem input)
          {
          m_history.prepend(input);
          }
          @
          or this (if the list should be pointing to const NBhistoryItems):
          @
          QList<const NBhistoryItem
          > m_list;

          void NBhistoryInterface::addHistoryItem(const NBhistoryItem *input)
          {
          m_history.prepend(input);
          }
          @

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nicky j
            wrote on last edited by
            #5

            Ok changed it to the first option you gave:

            @
            void NBhistoryInterface::addHistoryItem(NBhistoryItem *input)
            {
            qDebug() << "SLOT: NBhistoryInterface::addHistoryItem(const NBhistoryItem &input) STATUS: Called";
            m_history.prepend(input);
            qDebug() << "SLOT: NBhistoryInterface::addHistoryItem(const NBhistoryItem &input) STATUS: Completed";
            }
            @

            The program compiles then crashes. Heres what the crash report gives me:

            Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
            0 @BUNDLEIDENTIFIER@ 0x0000000100018364 QList<NBhistoryItem*>::prepend(NBhistoryItem* const&) + 20 (qlist.h:546)
            1 @BUNDLEIDENTIFIER@ 0x000000010001795e NBhistoryInterface::addHistoryItem(NBhistoryItem*) + 142 (nbhistory.cpp:

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              Did you recompile the everything in the code that uses that NBhistoryInterface::addHistoryItem() interface?

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nicky j
                wrote on last edited by
                #7

                yes, I believe everything has been recompiled. Maybe the problem has to do with the slot calling addHistoryItem(), but I don't think so. Here it is anyway though:
                @
                void NBhistoryInterface::addHistoryEntry(const QUrl &url)
                {
                QUrl historyUrl = url;
                NBhistoryItem *item = new NBhistoryItem("url", "title");
                addHistoryItem(item);
                }

                void NBhistoryInterface::addHistoryItem(NBhistoryItem *input)
                {
                qDebug() << "SLOT: NBhistoryInterface::addHistoryItem(const NBhistoryItem &input) STATUS: Called";
                m_history.prepend(input);
                qDebug() << "SLOT: NBhistoryInterface::addHistoryItem(const NBhistoryItem &input) STATUS: Completed";
                }

                QList<NBhistoryItem*> m_history;
                @

                Thanks for the help!

                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