Results 1 to 3 of 3

Thread: QByteArray::operator QNoImplicitBoolCast() const' is private

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QByteArray::operator QNoImplicitBoolCast() const' is private

    Qt Code:
    1. void rs485::rs485DataAquisition(QByteArray data) //0-SubSystem---------1-Pid--------2-Value
    2. {
    3. QByteArray receivedData;
    4. unsigned char address;
    5.  
    6. qDebug() << "rs485DataAquisition()" << data.toHex();
    7.  
    8. if(data.toHex() < "0x06")
    9.  
    10. if( data.toHex() < _ENGINEROOM_SUBS )
    11. {//Engine Compartment Elements
    12.  
    13. qDebug() << "Engine Compartment Elements";
    14.  
    15. if(data.size() == 1)
    16. {
    17. qDebug() << "Reading request..";
    18.  
    19. if(rs485WriteData(_READ_ENGINEADDRESS, data.toHex())) // I get the error here, the second parameter of this function is unsigned char
    20. {
    21. rs485Delay();
    22.  
    23. qDebug() << "NOW -> rs485CheckAck()";
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QByteArray::operator QNoImplicitBoolCast() const' is private

    The second parameter you are passing to that function is not unsigned char, it is a QByteArray. Further, the byte array you are using is a string representation of the bytes in the array in hex: a very different thing to the actual bytes that you almost certainly want to be sending. The first byte in the QByteArray is an unsigned char:
    Qt Code:
    1. if(rs485WriteData(_READ_ENGINEADDRESS, data.at(0)))
    To copy to clipboard, switch view to plain text mode 


    It seems you are generally confused about the difference between the value in a byte and the string representation of it. If you want to compare the value of the first byte in the QByteArray then do so directly, don't convert to a string and then compare. So, line 8 becomes:
    Qt Code:
    1. if (data.at(0) < 0x06) // notice no quotes and no toHex(), or
    2. if (data.at(0) < 6) // same thing in decimal
    To copy to clipboard, switch view to plain text mode 
    and line 10:
    Qt Code:
    1. if( data.toHex() < _ENGINEROOM_SUBS )
    To copy to clipboard, switch view to plain text mode 
    I am assuming that _READ_ENGINEADDRESS and _ENGINEROOM_SUBS are defined integer literals in hex like
    Qt Code:
    1. #define _READ_ENGINEADDRESS 0x06
    To copy to clipboard, switch view to plain text mode 
    which lead to think you needed to convert your byte array to a hex string.

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

    Default Re: QByteArray::operator QNoImplicitBoolCast() const' is private

    Just noticed a glitch in my last post. Line 10 should be something like:
    Qt Code:
    1. if( data.at(0) < _ENGINEROOM_SUBS )
    To copy to clipboard, switch view to plain text mode 
    where you select the appropriate byte from the array to compare.

Similar Threads

  1. Obtain const QImage from QByteArray
    By mcosta in forum Qt Programming
    Replies: 8
    Last Post: 27th April 2011, 09:46
  2. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  3. Replies: 3
    Last Post: 18th November 2010, 17:52
  4. Replies: 1
    Last Post: 29th September 2009, 19:44
  5. Replies: 2
    Last Post: 20th May 2006, 12:45

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.