Results 1 to 2 of 2

Thread: Ssending an int variable through serial using qextserialport

  1. #1

    Default Ssending an int variable through serial using qextserialport

    I am trying to send an int variable X though the serial port using qextserialport.

    After setting up and port initialization I use

    int x = 1;
    port->open(QIDevice::ReadWrite);
    port->write(x);

    but I am not receiving anything on the other end. What am I missing? Program compiles and run fine. The baud rate settings all match.
    Last edited by cnguyen; 31st May 2012 at 22:06.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Ssending an int variable through serial using qextserialport

    Which of the QIODevice::write() variants do you think accepts an int as its first argument? Your compiler will almost certainly be warning you about an " invalid conversion from ‘int’ to ‘const char*’ ", and mine flat out refused to compile this.

    To send an int you need to send the four bytes in an agreed order: and you need to get them into a form that you can write().

    Assuming you send write() valid parameters... the default operating mode of QExtSerialPort is event driven, so bytes are not sent until the program reaches the Qt event loop.

Similar Threads

  1. Replies: 5
    Last Post: 6th December 2011, 11:24
  2. Sending emails using Qt
    By homerun4711 in forum Newbie
    Replies: 5
    Last Post: 10th January 2011, 18:30
  3. sending quint32 variable in socket
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 24th June 2010, 02:56
  4. serial port printer sending commands, how?
    By triperzonak in forum Qt Programming
    Replies: 3
    Last Post: 6th April 2009, 15:51
  5. sending QImage over serial port
    By yagabey in forum Qt Programming
    Replies: 5
    Last Post: 16th January 2008, 22:38

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
  •  
Qt is a trademark of The Qt Company.