Thank you, I have found my problem now.
The problem is that I use the insert function. First I add COM4(goes in ports[4] so to speak) and then I insert COM1(at place 1).
What happens is that the COM4 port moves to place 5 in the list when you insert a port before it.
I got this example from the documentation:
QList<QString> list;
list << "alpha" << "beta" << "delta";
list.insert(2, "gamma");
// list: ["alpha", "beta", "gamma", "delta"]
Thank you again for your help, now I will check my code better before I think something is wrong with the library.
Best regards, Jurriaan