Writing binary data to file in Linux
First I would like to say that I'm not an expert on rfkill; so my comments are more general and may be slightly off for this specific case.

Despite the missing error handling (which you mention) I see only two problems. Not primarily with your code, but with your assumptions:


You are correct to avoid __attribute__((packed)), but the reasons are IMHO not correct. The main reasons in your linked document are unaligned access, data size and performance. None of this is really a showstopper for your code, because you are breaking the data up into its primitive types. More significant is IMHO the simple fact that __attribute__((packed)) is not portable. (Unless you remain on GCC only. On a microsoft compiler you would write #pragma pack(1))
I think you are wrong using the writeRawData() function. Because your code should handle both, big endian and little endian, you would want to use the streaming &lt;&lt; operator. I interpret the documentation like this: writeRawData() will always write in the machine byte order - big, or little endian - whatever the machine is. The streaming operators on the other hand will do a conversion, when necessary, to whatever endianness you have selected with setByteOrder().

There is another advantage using the streaming operators, you do not need to do ugly type casting. Instead of this:

out.writeRawData((char*)(&amp;(event.idx)), sizeof(event.idx))


you would simply write:

out &lt;&lt; event.idx;





Update: Error handling

I disagree with user1118321. I don't think that the QDataStream throws if it cannot write. I did not find anything about it in the documentation. (but the Qt documentation is known for having white spots) To handle write errors you can use the status() function. Or perhaps the functions from the underlying QIODevice. 

out.resetStatus();
out &lt;&lt; event.idx;
if(out.status() != QDataStream::Ok)
{
    // error handling
}