Error: reference to type 'NBhistoryItem *const' could not bind to an lvalue of type 'const NBhistoryItem *'
-
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!
-
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);
}
@ -
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: -
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!