memory mapped file help



  • I need some help regarding sharing data between two different applications made with Qt. Such data must reside on hard disk because I am not allowed to lose any information in case of energy failure.
    Is it possible to achieve this using a file mapped to memory?

    Anybody have an brief example or lineament?

    Thank you very much



  • @ivanperino

    You can use a QFile that inherits from QFileDevice

    Use the functions QFileDevice::map and unmap.



  • @TioRoy
    Thanks for your advice. I have read about QFile and its heritance. But speciffically I need an answer a bit more detailed:

    Am I able to share information without loosing anything in case of power failure? Because this is my purpose.
    One app uses data in file and ocassionally write data to it using a human interface. In the other hand, another app read and write data to the same file through serial port.
    I cannot use pipe nor socket because information would become volatile.

    The second question is about a simple example if anybody has some.

    Thankyou anyway

    Sincerely

    Ivan



  • Hi,

    a QFile is by default persistent so you can be sure to not loose information.
    BTW you have to synchronize the access to the file.

    Do you really need two application to do this work? In that case I suggest to

    1. The reader application reads data from serial port and sends them to the GUI using standard IPC

    2. The consumer store data on a file and use them



  • I understand your advice. 1 app access the file and the other app communicate directly to the first app. However, I aimed to use a memory-mapped-file just because I read some articles where it said this is one of the best practice to communicate two process without lossing information. Is this correct?

    I am really interested in your advices, so I present my case:

    GUI <-> MainAPP <-> SPortAPP

    GUI can be anything made for anybody with the only requirement of implementing a protocol/API to communicate to MainAPP. (e.g. sockets)
    MainAPP is my application who implement mathematics, logic, etc and defines the behaviour of my system. It cannot lose any information so I thought I might save it on a file.
    SPortAPP is a propietary protocol implementation whereby external systems read/write information to the database of MainAPP . This app shouldn't interact directly to MainAPP
    So, Such information must be available to read and write by both MainAPP and SPortAPP.

    what is your opinion about it? Do you reccomend any other type of implementation?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.