PDA

View Full Version : urgent!!!!!......sharing data



alphajoseph
19th January 2009, 08:28
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

lyuts
19th January 2009, 10:17
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

alphajoseph
20th January 2009, 05:19
frens
plz suggest some thing other than te QT tutorial at trolltech.com and the qt assistant.

wysota
20th January 2009, 07:41
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?

alphajoseph
27th January 2009, 06:14
please help me with creating a shared memory in a very descriptive way.
thanks a bunch

wysota
27th January 2009, 08:27
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?

alphajoseph
28th January 2009, 08:01
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

wysota
28th January 2009, 08:09
You have to attach to the segment using the same key you used when creating the segment in the other application:


// app 1:
QSharedMemory shm("mykey");
shm.create(4096);

// app 2:
QSharedMemory shm("mykey");
if(!shm.attach()){
qFatal("Couldn't attach to shared memory");
}

alphajoseph
29th January 2009, 09:04
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.



QBuffer qbuffer;
QString str="hi qt";
qbuffer.write(qPrintable(str));
int size = qbuffer.size();
QSharedMemory shm("mykey");
shm.create(4096);
shm.lock();
qbuffer.open(QBuffer::ReadWrite);
char *to = (char*)shm.data();
const char *from = qbuffer.data().data();
memcpy(to, from, qMin(shm.size(), size));
shm.unlock();
shm.detach();


app2 which reads


QBuffer qbuffer;
char ch[6];
qint64 si=9;
QSharedMemory shm("mykey");
if(!shm.attach())
qFatal("Couldn't attach to shared memory");
shm.lock();
qbuffer.open(QBuffer::ReadOnly);
qbuffer.setData((char*)shm.constData(), shm.size());
shm.unlock();
qbuffer.seek(0);
qbuffer.read(ch,si);
cout<<ch;

whats wrong with the code???

daemonna
16th September 2010, 11:42
dont detach memory in first program, coz if it's not attached in second, then it will be detached completely...

bool QSharedMemory::detach ()
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.