Results 1 to 2 of 2

Thread: Cannot understand program

  1. #1
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Cannot understand program

    Hello!

    I am trying to dissect a program and got stuck with one function:

    Qt Code:
    1. void SerialPortHandler::sendTrackPause()
    2. {
    3. // qDebug() << "sendTrackPause";
    4. QByteArray byteArr;
    5. QDataStream out(&byteArr, QIODevice::WriteOnly);
    6. out << ActionType::Track << TrackType::Pause << '\n';
    7. serial->write(byteArr);
    8. }
    To copy to clipboard, switch view to plain text mode 

    serial is an object of QSerialPort.
    This function clearly pauses a player.

    But what's going on under the hood?
    For what sake do we need QByteArray and QDataStream?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot understand program

    The QByteArray is not needed as the QSerialPort is also a QIODevice and the QDataStream could directly write into it.

    Depending on the types of ActionType::Track and TrackType::Pause it the QDataStream might just be used as a convenience wrapper to get multipe byte integered serialized in a specified byte order.

    Cheers,
    _

Similar Threads

  1. trying to understand qsettings ...
    By kerim in forum Newbie
    Replies: 7
    Last Post: 28th April 2011, 13:30
  2. Something i am not understand about Qt.
    By HeX0R in forum Newbie
    Replies: 8
    Last Post: 12th February 2010, 04:37
  3. need help .not able to understand.......
    By sh123 in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 01:50
  4. Replies: 6
    Last Post: 25th February 2008, 10:52
  5. don't understand Qt's setCodecForCStrings
    By ber_44 in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2007, 01:19

Tags for this Thread

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.