Results 1 to 3 of 3

Thread: QSharedMemory problem

  1. #1
    Join Date
    Feb 2010
    Location
    Poland
    Posts
    27
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QSharedMemory problem

    hi,
    i have small (i hope it's small) problem.

    at first i run process1 and after - process2.

    process1 code:
    Qt Code:
    1. QSharedMemory sharedMemory("foobar");
    2. sharedMemory.create(1024);
    3. sharedMemory.lock();
    4. QString *to = (QString*)sharedMemory.data();
    5. QString *text = new QString("hello world");
    6. memcpy(to, text, sizeof(*text));
    7. sharedMemory.unlock();
    To copy to clipboard, switch view to plain text mode 

    process2 code:
    Qt Code:
    1. QSharedMemory sharedMemory("foobar");
    2. sharedMemory.attach();
    3. sharedMemory.lock();
    4. QString *to = (QString*)sharedMemory.data();
    5. ui->plainTextEdit->setPlainText(*to);
    6. sharedMemory.unlock();
    To copy to clipboard, switch view to plain text mode 

    this code makes process2 crash.
    what's wrong with it?

    thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSharedMemory problem

    Try:
    Qt Code:
    1. QString to = QByteArray((char*)sharedMomory.constData(),sharedMomory,size());
    2. ui->plainTextEdit->setPlainText(to);
    To copy to clipboard, switch view to plain text mode 

    If you run your app in a debugger you will see which line exactly crashes, and why.
    Last edited by high_flyer; 18th November 2010 at 20:47.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2010
    Location
    Poland
    Posts
    27
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSharedMemory problem

    there
    http://www.qtcentre.org/threads/2625...-and-C-objects
    i found the reason why it doesn't work.

    thanks for your help

Similar Threads

  1. QSharedMemory and C++ objects
    By MattPhillips in forum Qt Programming
    Replies: 7
    Last Post: 29th November 2010, 07:42
  2. QsharedMemory or QsharedData ?
    By OverTheOCean in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2010, 22:33
  3. problem with qsharedmemory
    By daemonna in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2010, 12:54
  4. about the QSharedMemory
    By banban0802 in forum Qt Programming
    Replies: 5
    Last Post: 10th August 2010, 12:08
  5. new vs QSharedMemory
    By JovianGhost in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2010, 00:34

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.