diff --git a/CMakeLists.txt b/CMakeLists.txt index 91a04b9..377b080 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,6 +215,7 @@ set (wsjtx_CXXSRCS logbook/countrydat.cpp logbook/countriesworked.cpp logbook/logbook.cpp + fileutils.cpp psk_reporter.cpp Modulator.cpp Detector.cpp diff --git a/fileutils.cpp b/fileutils.cpp new file mode 100644 index 0000000..6ee7731 --- /dev/null +++ b/fileutils.cpp @@ -0,0 +1,11 @@ +#include "fileutils.h" + +void flushFileBuffer(const QFile &f){ +#ifdef Q_OS_WIN + FlushFileBuffers(reinterpret_cast(f.handle())); +#elif _POSIX_SYNCHRONIZED_IO > 0 + fdatasync(f.handle()); +#else + fsync(f.handle()); +#endif +} diff --git a/fileutils.h b/fileutils.h new file mode 100644 index 0000000..1dbf5de --- /dev/null +++ b/fileutils.h @@ -0,0 +1,14 @@ +#ifndef FILEUTILS_H +#define FILEUTILS_H + +#include +#ifdef Q_OS_WIN +# include +#else +# include +# include +#endif + +void flushFileBuffer(const QFile &f); + +#endif // FILEUTILS_H diff --git a/js8call.pro b/js8call.pro index cf775c2..4bb7b5f 100644 --- a/js8call.pro +++ b/js8call.pro @@ -93,7 +93,8 @@ SOURCES += \ DecoderThread.cpp \ Decoder.cpp \ APRSISClient.cpp \ - MessageServer.cpp + MessageServer.cpp \ + fileutils.cpp HEADERS += qt_helpers.hpp \ pimpl_h.hpp pimpl_impl.hpp \ @@ -137,7 +138,8 @@ HEADERS += qt_helpers.hpp \ DecoderThread.h \ Decoder.h \ APRSISClient.h \ - MessageServer.h + MessageServer.h \ + fileutils.h INCLUDEPATH += qmake_only diff --git a/logbook/adif.cpp b/logbook/adif.cpp index 9abd248..234901c 100644 --- a/logbook/adif.cpp +++ b/logbook/adif.cpp @@ -394,6 +394,7 @@ bool ADIF::addQSOToFile(QByteArray const& ADIF_record) out << ADIF_record << " " << endl; out.flush(); + flushFileBuffer(f2); f2.close(); } return true; diff --git a/logbook/adif.h b/logbook/adif.h index 04137fe..4de9af9 100644 --- a/logbook/adif.h +++ b/logbook/adif.h @@ -18,6 +18,8 @@ #include #endif +#include "fileutils.h" + class QDateTime; extern const QStringList ADIF_FIELDS; diff --git a/logqso.cpp b/logqso.cpp index 34d78ac..bc626da 100644 --- a/logqso.cpp +++ b/logqso.cpp @@ -318,6 +318,7 @@ void LogQSO::accept() QTextStream out(&f); out << logEntryItems.join(",") << endl; out.flush(); + flushFileBuffer(f); f.close(); }