Results 1 to 4 of 4

Thread: problem with saving QCstrings

  1. #1
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default problem with saving QCstrings

    hello everyone.. i am not sure what is wrong - never liked strings anyway!
    my problem is that i am trying to save a QCstring in a shared memory segment and i get a segmentation fault..
    here is the case statement that causes the trouble.. i could post the whole procedure but there is no point. similar case statements as the following one exisst in the procedure that save in the same memory segment (but at dif offest) floats, Q_UINT8 and other non string type of variables.

    Qt Code:
    1. case 4: //the scheduler capacitors are calling
    2. {
    3. struct schedStruct {
    4. Q_UINT8 c1TD;
    5. Q_UINT8 c2TD;
    6. Q_UINT8 c3TD;
    7. QCString c1OnDate;
    8. QCString c2OnDate;
    9. QCString c3OnDate;
    10. QCString c1OffDate;
    11. QCString c2OffDate;
    12. QCString c3OffDate;
    13. };
    14.  
    15. //lock the file for writing
    16. memset (&lock, 0, sizeof(lock));
    17. lock.l_type = F_WRLCK;
    18. fcntl (fd, F_SETLKW, &lock);
    19. printf("locked the file\n");
    20.  
    21. *((char*)file_memory+opcodeOffset) = 4;
    22. struct schedStruct *schedVar=(schedStruct*)((char*)file_memory + 0xCC);
    23. schedVar->c1TD=c1TimerDaily;
    24. schedVar->c2TD=c2TimerDaily;
    25. schedVar->c3TD=c3TimerDaily;
    26. printf("done with dailys\n");
    27. schedVar->c1OnDate=(c1TimerOnDate.local8Bit());
    28. printf("done with qcstring1On\n");
    29. schedVar->c2OnDate=c2TimerOnDate.local8Bit();
    30. schedVar->c3OnDate=c3TimerOnDate.local8Bit();
    31. schedVar->c1OffDate=c1TimerOffDate.local8Bit();
    32. schedVar->c2OffDate=c2TimerOffDate.local8Bit();
    33. schedVar->c3OffDate=c3TimerOffDate.local8Bit();
    34. printf("saved them");
    35.  
    36. //unlock the file to allow access
    37. lock.l_type = F_UNLCK;
    38. fcntl (fd, F_SETLKW, &lock);
    39. printf("unlocked\n");
    To copy to clipboard, switch view to plain text mode 

    file_memory is void* to the beginning of the sh.mem.segment.
    cXTimerDaily are unsigned chars
    and
    cXTimerOnDate, cXTimerOffDate are normal 16bit QStrings containing a date in the form:
    '08:00 - 01/01/2006' - ie just ascii chars therefore i should have no problem doing conversion to 8bit strings (as QCStrings are)..
    anyway,
    i run the gdb and i can get up to the line ' schedVar->c1OnDate=(c1TimerOnDate.local8Bit());'
    (between the 2 printf() lines).
    then i use the next command. here is as far as i get :

    Qt Code:
    1. 877 printf("done with dailys\n");
    2. (gdb) next
    3. done with dailys
    4. 249 { return (QCString&)assign( s ); }
    5. (gdb) next
    6. 79 { return (QMemArray<type>&)QGArray::assign(a); }
    7. (gdb) next
    8.  
    9. Program received signal SIGSEGV, Segmentation fault.
    10. 0xb7df1098 in QGArray::assign () from /usr/lib/qt/lib/libqt-mt.so.3
    11. (gdb)
    To copy to clipboard, switch view to plain text mode 

    any ideas how to tackle this?
    nass

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with saving QCstrings

    Don't store any data containing pointers in a shared segment if you intend to use it from another process - all pointers will become invalid. Only store serialised data. If you need to transfer a complex structure - convert it into a character string (serialise).

  3. #3
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with saving QCstrings

    Quote Originally Posted by wysota View Post
    Don't store any data containing pointers in a shared segment if you intend to use it from another process - all pointers will become invalid. Only store serialised data. If you need to transfer a complex structure - convert it into a character string (serialise).
    could you elaborate on this abit more?
    what and how do you mean to serialize the data?
    how can i do that? for the QCStrings case.. do i also need to serialize the three Q_UINT8 variables? or they are fine since they are not pointers to variables..?
    thank you for your help
    nass

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with saving QCstrings

    Quote Originally Posted by nass View Post
    could you elaborate on this abit more?
    what and how do you mean to serialize the data?
    how can i do that?
    http://en.wikipedia.org/wiki/Serialization
    do i also need to serialize the three Q_UINT8 variables? or they are fine since they are not pointers to variables..?
    They are fine.

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  3. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Record update windowd entered data saving
    By MarkoSan in forum Qt Programming
    Replies: 56
    Last Post: 18th January 2006, 18:50

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.