Results 1 to 10 of 10

Thread: urgent!!!!!......sharing data

  1. #1
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default urgent!!!!!......sharing data

    frens
    I will be very happy if someone could help me out.
    I am retrieving data from a network and i want that data to be available for other applications to access...

    for eg: i want retrieved values to be available for inserting into a mysql table.

    the soln sud be some interprocess commn right?

    plz suggest a very simple example.
    thanks a lot
    Last edited by alphajoseph; 19th January 2009 at 09:00.

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: urgent!!!!!......sharing data

    If you want all applications to "see" this data then, I guess, shared memory will be useful.
    http://doc.trolltech.com/4.4/qsharedmemory.html
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: urgent!!!!!......sharing data

    frens
    plz suggest some thing other than te QT tutorial at trolltech.com and the qt assistant.

  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: urgent!!!!!......sharing data

    I have a few hints for you:

    1. Never use the word "urgent" in thread titles or thread content - it immediately causes many people to skip your question or leave it for later.
    2. Don't underestimate Assistant and Qt Reference - it's the best source of help you are going to get, so live with it.
    3. Try expressing your questions in a less general and more specific manner - the more general your question is, the further from your goal answers will be.
    4. Don't use trash talk and express yourself in simple full sentences if you want to be understood.
    5. It's Qt, not QT - the latter is Apple's video technology.
    6. If you have a basic question or you want the answer to be very simple, consider yourself a newbie and post in the newbie section (I'm moving the thread there).

    Now, what is the exact problem?

  5. #5
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: sharing data

    please help me with creating a shared memory in a very descriptive way.
    thanks a bunch

  6. #6
    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: sharing data

    You really won't get an answer if you ask such general questions. Could you state specifically what you want? What exact help do you need? What have you already tried?

  7. #7
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: sharing data

    i created a shared memory
    Now i dont know how to acces it from another program(there is no starting address nor any ending address option of shared memory available in Qt)
    Any help is appreciated
    Thanks

  8. #8
    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: sharing data

    You have to attach to the segment using the same key you used when creating the segment in the other application:

    Qt Code:
    1. // app 1:
    2. QSharedMemory shm("mykey");
    3. shm.create(4096);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // app 2:
    2. QSharedMemory shm("mykey");
    3. if(!shm.attach()){
    4. qFatal("Couldn't attach to shared memory");
    5. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: sharing data

    i tried that ,but couldn't write even a simple text.
    here below is my code.

    app1 which creates and writes into the shared memory.

    Qt Code:
    1. QBuffer qbuffer;
    2. QString str="hi qt";
    3. qbuffer.write(qPrintable(str));
    4. int size = qbuffer.size();
    5. QSharedMemory shm("mykey");
    6. shm.create(4096);
    7. shm.lock();
    8. qbuffer.open(QBuffer::ReadWrite);
    9. char *to = (char*)shm.data();
    10. const char *from = qbuffer.data().data();
    11. memcpy(to, from, qMin(shm.size(), size));
    12. shm.unlock();
    13. shm.detach();
    To copy to clipboard, switch view to plain text mode 

    app2 which reads
    Qt Code:
    1. QBuffer qbuffer;
    2. char ch[6];
    3. qint64 si=9;
    4. QSharedMemory shm("mykey");
    5. if(!shm.attach())
    6. qFatal("Couldn't attach to shared memory");
    7. shm.lock();
    8. qbuffer.open(QBuffer::ReadOnly);
    9. qbuffer.setData((char*)shm.constData(), shm.size());
    10. shm.unlock();
    11. qbuffer.seek(0);
    12. qbuffer.read(ch,si);
    13. cout<<ch;
    To copy to clipboard, switch view to plain text mode 
    whats wrong with the code???

  10. #10
    Join Date
    May 2010
    Location
    slovakia
    Posts
    47
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: sharing data

    dont detach memory in first program, coz if it's not attached in second, then it will be detached completely...

    code Code:
    1. bool QSharedMemory::detach ()
    2. Detaches the process from the shared memory segment. If this was the last process attached to the shared memory segment, then the shared memory segment is released by the system, i.e., the contents are destroyed.
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Sharing data between threads
    By bbui210 in forum Qt Programming
    Replies: 15
    Last Post: 19th October 2008, 17:56
  2. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  3. Sharing data across threads
    By jphn_crichton in forum Qt Programming
    Replies: 11
    Last Post: 5th May 2008, 18:29
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.