Reputation: 59
I want to compare two Qlist say
QList<QSerialPortInfo> port1;
QList<QSerialPortInfo> port2;
I want to implement it in if
condition such that
if (port1 != port2)
{
// do something
}
but it seems that it doesn't work like that I have read the documentation for QList and there is this member
operator!=(const QList<T> &other) const
Any Idea how to implement it, please don't go and say ohh I am not going to give you the solution but here is a tip. I am not a student and this is not a homework. I am doing my own project in Qt. thanks guys.
Upvotes: 2
Views: 1336
Reputation: 12899
From the QList<T>::operator!=
documentation...
This function requires the value type to have an implementation of operator==().
Unfortunately there is no valid operator==
defined for QSerialPortInfo
but you can easily implement your own...
bool operator== (const QSerialPortInfo &lhs, const QSerialPortInfo &rhs)
{
return lhs.manufacturer() == rhs.manufacturer()
&& lhs.serialNumber() == rhs.serialNumber();
}
The code shown assumes that a QSerialPortInfo
instance can be uniquely identified by its manufacturer and serial number.
Upvotes: 5