Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. readRawData
Forum Update on Monday, May 27th 2025

readRawData

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 507 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jipe3001J Offline
    jipe3001J Offline
    jipe3001
    wrote on last edited by
    #1

    I am using the readRawData to read a file as follows:

    char *date1 = new char[10];
    in.readRawData(date1,10);
    qDebug() << "date"<<date1;
    

    but despite the specified length of 10 chars, I've got the following result with QDebug:

    date 1807120942??????
    

    I am wandering why these question marks after 10 chars?

    The view from the Debugger is shown below:

    	date1	"1807120942������"	char*
    			'1' 	49    	0x31	char
    			'8' 	56    	0x38	char
    			'0' 	48    	0x30	char
    			'7' 	55    	0x37	char
    			'1' 	49    	0x31	char
    			'2' 	50    	0x32	char
    			'0' 	48    	0x30	char
    			'9' 	57    	0x39	char
    			'4' 	52    	0x34	char
    			'2' 	50    	0x32	char
    			'○' 	-18/238	0xee	char
    			    	-2/254	0xfe	char
    			'○' 	-18/238	0xee	char
    			    	-2/254	0xfe	char
    			'○' 	-18/238	0xee	char
    			    	-2/254	0xfe	char
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      qDebug() with char* uses std::strlen to determine the lenght of the string. If you don't null-terminate it it will continue reading your memory until it finds a byte set at 0

      char *date1 = new char[11];
      date1[10]='\0';
      in.readRawData(date1,10);
      qDebug() << "date"<<date1;
      

      Or using Qt's convenient QByteArray

      QByteArray date1(10,0);
      in.readRawData(date1.data(),10);
      qDebug() << "date"<<date1;
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • jipe3001J Offline
        jipe3001J Offline
        jipe3001
        wrote on last edited by
        #3

        Thanks VRonin for your quck answer, it's now working perfectly !

        I am wandering what are the two arguments in the QByteArray definition:
        (can't find it in the doc !!)

        QByteArray date1(10,0);

        I guess 10 is the size of the array but what is the zero standing for?

        Thks again for your help

        J.HilkJ 1 Reply Last reply
        0
        • jipe3001J jipe3001

          Thanks VRonin for your quck answer, it's now working perfectly !

          I am wandering what are the two arguments in the QByteArray definition:
          (can't find it in the doc !!)

          QByteArray date1(10,0);

          I guess 10 is the size of the array but what is the zero standing for?

          Thks again for your help

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @jipe3001
          reading the decumentation is helpful, Qt, has one of the best out there.

          link QByteArray


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved