PDA

View Full Version : QSerialDevice enumerator deletion question



marcvanriet
19th December 2011, 23:26
I have a question about SerialDeviceEnumerator. Since it is mentioned here A LOT, I think (hope) I can ask it in this forum.

The enumerator object gets created automatically using the static instance() method, which creates an instance of the object and remembers this in SerialDeviceEnumerator::self.

However, when does this object ever gets deleted ? At the end of the program, the destructor for SerialDeviceEnumerator::self will NOT be called because it is just a pointer, not an instance.

I don't see anything in the enumerator example to delete the instance either.

Best regards,
Marc

kuzulis
20th December 2011, 13:43
Upon completion of the application, the OS itself will remove all.
No need to call the destructor.

PS:
This version of the library is outdated.
Instead it use of version 2.0, as it will be included in Qt as a addon.
Already in progress preparatory work for the integration.

marcvanriet
21st December 2011, 00:10
Hi,

I went to http://gitorious.org/qserialdevice and took a copy of the master branch. Isn't this the latest then ?

In my opinion, it is a rather 'dirty' programming practice to just let the OS clean up all the handles you left open... :( Especially in a cross-platform environment like Qt where not every OS may behave as expected. Maybe you could consider the Meyers approach (http://www.codeproject.com/KB/architecture/singleton.aspx) for the singleton pattern.

Regards,
Marc

kuzulis
21st December 2011, 07:04
I went to http://gitorious.org/qserialdevice and took a copy of the master branch. Isn't this the latest then ?
No, master branch is the old library to the old API, as with version 0.3 and 0.4.

The new branch 2.0 is completely different, has a different API, which is radically different from the old API.
The difference is in the name, count and functionality of its constituent classes,
as well as extensive support for new operating systems.

See simply wiki: http://gitorious.org/qserialdevice/pages/Home
Direct link to 2.0: http://gitorious.org/qserialdevice/qserialdevice/trees/2.0


In my opinion, it is a rather 'dirty' programming practice to just let the OS clean up all the handles you left open... Especially in a cross-platform environment like Qt where not every OS may behave as expected. Maybe you could consider the Meyers approach for the singleton pattern.
I know it's dirty. But since memory is allocated only once - then the dirt is not so dirty. :)
The new library, this class of functional and removed. So do not worry. :)

marcvanriet
28th December 2011, 01:48
Hi kuzulis,

Is the 2.0 branch fully functional ? I started a very simple 'terminal' like program, and it seems to me that the readyRead() signal is not always emitted.

I send a text command to a device, and it sends me about 20 lines of text. On the first readyRead(), about 6 lines are in the buffer and I read it all. There is no readyRead() signal for data arriving after this. When I send a new command, readyRead() fires again, and then I see the remaining data.

I have put a small example program in attachment. Only the com_data_available() and on_leCmd_returnPressed() functions are relevant. The .pro file will need to be adapted to include SerialPort on your computer. I'm using Windows.

Best regards,
Marc