1

I have an issue with QList as a function parameter and I'll be glad if you can assist me.

I have this code for example:

void SpinBoxList_Enable(QList<QWidget *> *spinBoxList)
{
    foreach(QWidget* mWidget,*spinBoxList)
        mWidget->setEnabled(false);
}

and in the implemantation file I use the QList<QWidget *> variable as a pointer:

SpinBoxList_Enable(&controlBoardSpinBoxList);

(controlBoardSpinBoxList is a variable of QList<QWidget *>).

The Function ToggleBoards_Slot(bool) is a slot that uses. When I compile, I get this error message:

1>cmosaixserialnumber.obj : error LNK2019: unresolved external symbol "private: void __cdecl CMosaixSerialNumber::SpinBoxList_Disable(class QList<class QWidget *> *)" (?SpinBoxList_Disable@CMosaixSerialNumber@@AEAAXPEAV?$QList@PEAVQWidget@@@@@Z) referenced in function "public: void __cdecl CMosaixSerialNumber::ToggleBoards_Slot(bool)" (?ToggleBoards_Slot@CMosaixSerialNumber@@QEAAX_N@Z)
1>cmosaixserialnumber.obj : error LNK2019: unresolved external symbol "private: void __cdecl CMosaixSerialNumber::SpinBoxList_Enable(class QList<class QWidget *> *)" (?SpinBoxList_Enable@CMosaixSerialNumber@@AEAAXPEAV?$QList@PEAVQWidget@@@@@Z) referenced in function "private: void __cdecl CMosaixSerialNumber::on_ControlBoardCheckBox_StateChanged(int)" (?on_ControlBoardCheckBox_StateChanged@CMosaixSerialNumber@@AEAAXH@Z)

How can I fix this?

Mat
  • 202,337
  • 40
  • 393
  • 406
EVH671
  • 251
  • 2
  • 6
  • 20

2 Answers2

1

You call the function with a pointer, but the function argument is not a pointer. I recommend you change the argument to a reference (to avoid copying):

void SpinBoxList_Enable(QList& spinBoxList) { ... }

Then call it without using the address-of operator:

SpinBoxList_Enable(controlBoardSpinBoxList);
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • And also `*spinBoxList` in the function body needs to be corrected. – Pavel Strakhov Jun 30 '13 at 10:20
  • Hi Joachim, I did this now I get this error message: 1>cmosaixserialnumber.obj : error LNK2019: unresolved external symbol "private: void __cdecl CMosaixSerialNumber::SpinBoxList_Disable(class QList &)" (?SpinBoxList_Disable@CMosaixSerialNumber@@AEAAXAEAV?$QList@PEAVQWidget@@@@@Z) referenced in function "public: void __cdecl CMosaixSerialNumber::ToggleBoards_Slot(bool)" (?ToggleBoards_Slot@CMosaixSerialNumber@@QEAAX_N@Z) – EVH671 Jun 30 '13 at 10:38
  • 1>cmosaixserialnumber.obj : error LNK2019: unresolved external symbol "private: void __cdecl CMosaixSerialNumber::SpinBoxList_Enable(class QList &)" (?SpinBoxList_Enable@CMosaixSerialNumber@@AEAAXAEAV?$QList@PEAVQWidget@@@@@Z) referenced in function "private: void __cdecl CMosaixSerialNumber::on_ControlBoardCheckBox_StateChanged(int)" (?on_ControlBoardCheckBox_StateChanged@CMosaixSerialNumber@@AEAAXH@Z) – EVH671 Jun 30 '13 at 10:38
  • 2
    I'd use const QList& though – Frank Osterfeld Jun 30 '13 at 11:59
0

Containers in Qt are reference counted and implicitly shared for reading. You don't need to pass a QList as a pointer, you don't even need to pass it as a reference (as Joachim suggested), even though this is the usual and GOOD practice with containers (especially STL which are otherwise deep-copied).

You can pass the actual QList and it won't be copied as long as you only read from it, if you attempt a writing operation, it will then create a copy and write to it instead. Read more on this here.

dtech
  • 47,916
  • 17
  • 112
  • 190