Opening mutliple ports in one class with Qt c++

169 views
Skip to first unread message

Jurriaan Petersen

unread,
Feb 19, 2013, 7:59:35 AM2/19/13
to qextser...@googlegroups.com
Hello everybody,

I'm using your library for a school project with great results until I hit a problem. In a class I have a QList of QextSerialPort pointers, each pointer represents a port(COM1,COM2, etc...).
When I open a port everything works great but a problem arises when I open a second one, and then try to use the first one again. If I do this the application crashes.
Do I need separate enumerators for each port? Is the library capable of opening multiple ports? Should I use a different approach?
Thanks in advance,

Best regards, Jurriaan

1+1=2

unread,
Feb 19, 2013, 8:23:49 PM2/19/13
to qextser...@googlegroups.com
Hi Jurriaan,

About ten serial port opened at the same time in one of my application which still works well, perhaps the problem caused by other parts of  
your code.

Maybe some code snippet is useful.

Regards,

Debao



--
You received this message because you are subscribed to the Google Groups "qextserialport" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qextserialpor...@googlegroups.com.
To post to this group, send email to qextser...@googlegroups.com.
Visit this group at http://groups.google.com/group/qextserialport?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jurriaan Petersen

unread,
Feb 20, 2013, 2:04:48 AM2/20/13
to qextser...@googlegroups.com
Hello Debao,

Thank you for your reply, I'm glad to hear that the library supports multiple ports.
I have attached the source file which I use. I have a feeling that the problem lies in the enumerator.
Hopefully you can help me out,

Best regards, Jurriaan
rs232.cpp

1+1=2

unread,
Feb 20, 2013, 2:51:59 AM2/20/13
to qextser...@googlegroups.com
Hi,

Seems that the usage of QList is wrong.

First, you creat a QList and fill it with 10 NULL.

    for(int i = 0 ; i < 10 ; i++){
        ports.append(NULL);
    }


Then, you insert *several* Qesp pointer to it. (The problem is in which order ?)

    QextSerialPort *port = new QextSerialPort(comPortString,ps);
    port->open(QIODevice::ReadWrite);
    ports.insert(comPort,port);

And finally, you try to extract the pointer using QList::at()

        if(ports.at(comPort)->isOpen()){
    ....

By the way, you can give a try to QMap or QHash instead of QList.


Regards,

Jurriaan Petersen

unread,
Feb 20, 2013, 3:51:14 AM2/20/13
to qextser...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages