Results 1 to 4 of 4

Thread: Reinterpret cast can fail on a structure with char array inside it =

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: Reinterpret cast can fail on a structure with char array inside it =

    Thanks Here you are

    Qt Code:
    1. struct W__header {
    2. int number;
    3. char title [200];
    4. double inicial, final;
    5. int num;
    6. float interval;
    7. };
    To copy to clipboard, switch view to plain text mode 

    To set the title I have ( I think here is the problem :
    Qt Code:
    1. void set_title(std::string txt) {
    2. strncpy(title,texto.c_str(),200) ; }
    To copy to clipboard, switch view to plain text mode 

    And my 'put' function :

    Qt Code:
    1. template <class TTput_stream>
    2. void W_inpout::W_stream::put (TTput_stream &value) {
    3. loc+= sizeof value; it works fine
    4. lof=loc;
    5. const char * buffer ;
    6. buffer = reinterpret_cast<const char*> (&value);
    7. }
    To copy to clipboard, switch view to plain text mode 

    I user put(my_class->header);

    The buffer and the function works fine with my other structures.
    At debugger I see title filled with the std::text passed to ser_title an a lot of \0 until the end of var

    Maybe reinterpret_cast does not work becase the structure has the char 'title' inside it ?


    Any help would be appreciated.
    Last edited by tonnot; 15th July 2011 at 18:16.

Similar Threads

  1. Char array[6] to QString and display it
    By arunvv in forum Newbie
    Replies: 11
    Last Post: 12th March 2014, 20:48
  2. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  3. Cast to const char *
    By brevleq in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2009, 09:39
  4. Conversion Char Array to string
    By anafor2004 in forum Newbie
    Replies: 6
    Last Post: 6th May 2008, 14:35
  5. Char Array to QString
    By 3nc31 in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2007, 22:18

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.