Added cpp style mechanisme to queue callables on window thread.
This commit is contained in:
parent
8af6bc4ac5
commit
2432be9d72
2 changed files with 52 additions and 1 deletions
23
mainwindow.h
23
mainwindow.h
|
|
@ -22,15 +22,36 @@ namespace Pgsql {
|
|||
|
||||
}
|
||||
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
|
||||
class TaskQueue {
|
||||
public:
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using callable = std::function<void()>;
|
||||
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
/* Meant to be called from other threads to pass a code block
|
||||
* that has to be executed in the context of the thread of the window.
|
||||
*/
|
||||
void QueueTask(callable c);
|
||||
|
||||
private:
|
||||
using t_CallableQueue = std::deque<callable>;
|
||||
std::mutex m_mutexCallableQueue;
|
||||
t_CallableQueue m_callableQueue;
|
||||
|
||||
|
||||
std::unique_ptr<Ui::MainWindow> ui;
|
||||
std::unique_ptr<SqlHighlighter> highlighter;
|
||||
|
||||
|
|
@ -65,7 +86,7 @@ private slots:
|
|||
void cancel_query();
|
||||
void receiveNotice(Pgsql::ErrorDetails notice);
|
||||
|
||||
|
||||
void processCallableQueue();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue