diff --git a/main.cpp b/main.cpp index 4bf16f144..a28f1c686 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,8 @@ #include #include "mainwindow.h" +QSharedMemory mem_jt9("mem_jt9"); + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -18,7 +20,20 @@ int main(int argc, char *argv[]) a.setFont(font); } - MainWindow w; + // Create and initialize shared memory segment + if(!mem_jt9.attach()) { + if (!mem_jt9.create(sizeof(jt9com_))) { + QMessageBox::critical( 0, "Error", "Unable to create shared memory segment."); + exit(1); + } + } + char *to = (char*)mem_jt9.data(); + int size=sizeof(jt9com_); + if(jt9com_.newdat==0) { + } + memset(to,0,size); //Zero all decoding params in shared memory + + MainWindow w(&mem_jt9); w.show(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 2b828188b..383e1f474 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,14 +21,13 @@ double dFreq[]={0.136,0.4742,1.838,3.578,5.357,7.078,10.130,14.078, 18.104,21.078,24.918,28.078,50.293,70.091,144.489,432.178}; WideGraph* g_pWideGraph = NULL; -QSharedMemory mem_jt9("mem_jt9"); QString rev="$Rev$"; QString Program_Title_Version=" WSJT-X v0.9, r" + rev.mid(6,4) + " by K1JT"; //-------------------------------------------------- MainWindow constructor -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -193,6 +192,8 @@ MainWindow::MainWindow(QWidget *parent) : QString::number(iret)); } #endif + mem_jt9 = shdmem; + /* if(!mem_jt9.attach()) { if (!mem_jt9.create(sizeof(jt9com_))) { msgBox("Unable to create shared memory segment."); @@ -203,6 +204,7 @@ MainWindow::MainWindow(QWidget *parent) : if(jt9com_.newdat==0) { } memset(to,0,size); //Zero all decoding params in shared memory +*/ PaError paerr=Pa_Initialize(); //Initialize Portaudio if(paerr!=paNoError) { @@ -895,7 +897,7 @@ void MainWindow::OnExit() { g_pWideGraph->saveSettings(); m_killAll=true; - mem_jt9.detach(); + mem_jt9->detach(); QFile quitFile(m_appDir + "/.quit"); quitFile.open(QIODevice::ReadWrite); QFile lockFile(m_appDir + "/.lock"); @@ -1154,7 +1156,7 @@ void MainWindow::decode() //decode() //newdat=1 ==> this is new data, must do the big FFT //nagain=1 ==> decode only at fQSO +/- Tol - char *to = (char*)mem_jt9.data(); + char *to = (char*)mem_jt9->data(); char *from = (char*) jt9com_.ss; int size=sizeof(jt9com_); if(jt9com_.newdat==0) { @@ -1163,7 +1165,7 @@ void MainWindow::decode() //decode() from += noffset; size -= noffset; } - memcpy(to, from, qMin(mem_jt9.size(), size)); + memcpy(to, from, qMin(mem_jt9->size(), size)); QFile lockFile(m_appDir + "/.lock"); // Allow jt9 to start lockFile.remove(); diff --git a/mainwindow.h b/mainwindow.h index 443300a4e..03f20e3ce 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -21,7 +21,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QSharedMemory *shdmem, QWidget *parent = 0); ~MainWindow(); public slots: @@ -309,6 +309,8 @@ private: SoundInThread soundInThread; //Instantiate the audio threads SoundOutThread soundOutThread; + QSharedMemory *mem_jt9; + //---------------------------------------------------- private functions void readSettings(); void writeSettings();