Results 1 to 11 of 11

Thread: qsharedmemory between Qt and c program on linux plateform

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    5
    Platforms
    Unix/X11

    Default qsharedmemory between Qt and c program on linux plateform

    Hi everybody
    I 'm beginner in Qt, I have a problem to read a shared memory segment generated by c program on qt application using nativekey().
    if someone have any idea or solution please help me
    my c prog generate a data on shared memory with this key-id 0x00313233
    and this is my source :

    Qt Code:
    1. QSharedMemory shm("123");
    2. if (shm.isAttached())
    3. shm.detach();
    4. if (!shm.attach(QSharedMemory::ReadWrite)) {
    5. // Shared memory n'est pas crée donc création
    6. if (!shm.create(1024, QSharedMemory::ReadWrite)) {
    7. QSharedMemory::SharedMemoryError err = shm.error();
    8. qDebug()<< err <<"Erreur lors de création de shared memory";
    9. }
    10. else {
    11. qDebug()<< "memory attached successfully";
    12. qDebug()<< "memory created successfully";
    13. qDebug()<< "memory keyid"<<shm.key().toAscii().toHex();
    14.  
    15. if(shm.lock()){
    16. qDebug()<<"Memory locked successefully";
    17. QByteArray s = QByteArray((char*) shm.constData(), shm.size());
    18. QString message = QString::fromUtf8(s.constData());
    19. qDebug() << message;
    20.  
    21. if(shm.unlock()){
    22. qDebug()<< "Memory unlocked successefully";
    23. if(shm.detach())
    24. qDebug()<<"Memory detached successefully";
    25. else qDebug()<<"Memory detached failed"<< shm.error();
    26. }
    27. else qDebug()<< "Memory unlock failed"<< shm.error();
    28. }
    29. else qDebug()<<"Memory lock failed"<< shm.error();
    30. }
    31. }
    32.  
    33.  
    34. QTextEdit *textedit= new QTextEdit(s);
    35. QHBoxLayout *layout = new QHBoxLayout( &mainwindow );
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 10th May 2012 at 00:22. Reason: missing [code] tags

Similar Threads

  1. My first Linux QT program wont compile
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 27th October 2010, 15:49
  2. How to shutdown Linux machine from QT Program?
    By Kevin Hoang in forum Qt Programming
    Replies: 3
    Last Post: 20th August 2010, 20:42
  3. Replies: 2
    Last Post: 22nd March 2010, 08:54
  4. Program in Windows, Deploy in Linux
    By suitto in forum Installation and Deployment
    Replies: 1
    Last Post: 8th April 2009, 13:11
  5. QT Program debug,GDB on Linux
    By darpan in forum General Programming
    Replies: 1
    Last Post: 26th January 2007, 22:02

Tags for this Thread

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.