Results 1 to 20 of 20

Thread: How to write bytes read from serial port to a QFile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to write bytes read from serial port to a QFile

    some comments:
    1. why do you allocate the serial port on the stack?
    make it a member, this way you don't need to allocate it in every method, and better on the heap.
    It is dengeraus to do it the way you do.
    2. why don't you use QDataStream on the serial port?
    3. you want to use isOpen() not open() :
    Qt Code:
    1. if(sp.isOpen()) //here
    2. {
    3. qWarning("port still open after closing");
    4. }
    To copy to clipboard, switch view to plain text mode 

    It could well be that once you fix these points, the problem will go away, if not, posts again.

    Another point:
    You don't need to use Posix_QexSerial port, it is not portable.
    Use QextSerialPort, and give the _TTY_POSIX_ flag in the make file.
    This way your code will compile on windows as well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to write bytes read from serial port to a QFile

    why do you allocate the serial port on the stack?
    make it a member, this way you don't need to allocate it in every method, and better on the heap.
    how to allocate it on heap??
    all i have done is made it a global member like this --->

    Qt Code:
    1. Posix_QextSerialPort *sp = new Posix_QextSerialPort("/dev/ttyS0");
    To copy to clipboard, switch view to plain text mode 

    but its still not working. the error is the same.
    There are 10 kinds of people in this world. Those who understand binary, and those who dont.

    regards
    shamik

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to write bytes read from serial port to a QFile

    why global? why not make it a member?
    And yes, use 'new' to allocate on the heap, and don't forget to use 'delete' when you don't need the object anymore (or just give it Qt object parent).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.