-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd506a1
commit f9b6596
Showing
12 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "ExampleBackend.h" | ||
|
||
#include <QThread> | ||
#include <QDebug> | ||
|
||
|
||
ExampleBackend::ExampleBackend(QObject* parent) | ||
:QThread(parent) | ||
{ | ||
connect(this, &QThread::finished, [=]() { deleteLater(); }); | ||
} | ||
|
||
ExampleBackend::~ExampleBackend() | ||
{ | ||
} | ||
|
||
void ExampleBackend::stopAndClear() | ||
{ | ||
quit(); | ||
wait(); | ||
} | ||
|
||
void ExampleBackend::quit() | ||
{ | ||
bIsQuit = true; | ||
generateNewData.unlock(); | ||
|
||
QThread::quit(); | ||
} | ||
|
||
void ExampleBackend::copyingCompleted() | ||
{ | ||
generateNewData.unlock(); | ||
} | ||
|
||
void ExampleBackend::run() | ||
{ | ||
int size = 512; | ||
double* data = new double[size]; | ||
double d = 0; | ||
bIsQuit = false; | ||
|
||
while(!bIsQuit) | ||
{ | ||
generateNewData.lock(); | ||
|
||
if (bIsQuit) break; | ||
|
||
d = (rand() % 4 + 2); | ||
for(int i = 0; i < size; i++) | ||
{ | ||
data[i] = sin(i / (size/d)) * 100.0; | ||
} | ||
|
||
emit generatedNewData(data, size); | ||
} | ||
|
||
generateNewData.unlock(); | ||
delete data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <QMutex> | ||
#include <QThread> | ||
|
||
class ExampleBackend : public QThread | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
ExampleBackend(QObject* parent = nullptr); | ||
~ExampleBackend(); | ||
|
||
void stopAndClear(); | ||
void quit(); | ||
|
||
signals: | ||
void generatedNewData(double* data, int size); | ||
|
||
public slots: | ||
void copyingCompleted(); | ||
|
||
protected: | ||
void run() override; | ||
|
||
private: | ||
QMutex generateNewData; | ||
bool bIsQuit; | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
|
||
#include <QApplication> | ||
#include "Frontend/MainWindow/MainWindow.h" | ||
#include "Backend/ExampleBackend.h" | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
int main(int argc, char* argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
QApplication app(argc, argv); | ||
MainWindow w; | ||
|
||
w.setWindowTitle("QtPlot Example"); | ||
w.show(); | ||
return a.exec(); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters