Reputation: 520
I am going through a Qt Project, and I am unable to understand a part of the code on QList. In the following code, I know what Q_ASSERT does. I have misunderstanding what does my List called keyItemPairs will store?
void NTCommunicationController::processStartupMessage(const QJsonObject ¶ms)
{
Q_ASSERT(m_systemSettings);
QList<QPair<QString, NTEditorModelItem*>> keyItemPairs =
{{QString(NTParameterSetMessage::SU_BSP_VERSION), m_systemSettings->getBspVersion()},
{QString(NTParameterSetMessage::SU_KERNEL_VERSION), m_systemSettings->getKernelVersion()},
{QString(NTParameterSetMessage::SU_APP_VERSION), m_systemSettings->getApplicationVersion()},
{QString(NTParameterSetMessage::SU_FW_VERSION), m_systemSettings->getFirmwareVersion()},
{QString(NTParameterSetMessage::SU_PIN_CODE), m_systemSettings->getPincodeSetting()}
};
applyValuesToModelItems(params, keyItemPairs, true);
}
Upvotes: 0
Views: 63
Reputation: 1536
It stores exactly what its name tells you. It is a list of objects where each element is a pair of values. In this particular case QPair<QString, NTEditorModelItem*>
.
Think of a QPair<>
(or analogue std::pair<>
) as a way of storing two associated values inside a single object.
You could achieve the same using a struct with two fields if you're more familiar with such approach. For example:
struct Entry {
QString value;
NTEditorModelItem* model;
};
QList<Entry> items = {{NTParameterSetMessage::SU_BSP_VERSION, m_systemSettings->getBspVersion()},
{NTParameterSetMessage::SU_KERNEL_VERSION), m_systemSettings->getKernelVersion()}
}
You get pretty much the same functionality. However, using a pair template you don't have to create a separate struct just to bind the values together.
Upvotes: 3
Reputation: 81
As shown in the code, the list stores items of type QPair<QString, NTEditorModelItem*>
.
It is initialized with 5 values. First one is (NTParameterSetMessage::SU_BSP_VERSION), m_systemSettings->getBspVersion())
Upvotes: 1