Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 042067e6 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Use regular pthread to run QApplication

parent fe16e882
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!186Add the Qt window module as an alternative to the SDL2 module
...@@ -189,7 +189,6 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d ...@@ -189,7 +189,6 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d
(void)mod_free; (void)mod_free;
(void)mod_close; (void)mod_close;
RETURN_UNLESS(win, "Invalid arguments", false); RETURN_UNLESS(win, "Invalid arguments", false);
struct poller_thread_arg *arg;
if (*win == nullptr) { if (*win == nullptr) {
*win = LKT_ALLOC_STRUCT(module_qt_window_s); *win = LKT_ALLOC_STRUCT(module_qt_window_s);
...@@ -200,11 +199,8 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d ...@@ -200,11 +199,8 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d
(*win)->db = db; (*win)->db = db;
(*win)->reg = qt_window_reg; (*win)->reg = qt_window_reg;
arg = LKT_ALLOC_STRUCT(poller_thread_arg); pthread_t thread;
RETURN_UNLESS(arg, "Out of memory", false); RETURN_IF(pthread_create(&thread, nullptr, ___create_mpv_widget, *win), "Failed to launch the Qt thread", false);
arg->args = *win;
RETURN_IF(poller_new(&(*win)->self, ___create_mpv_widget, arg),
"Failed to launch the SDL thread", false);
} }
return true; return true;
......
#include "mainwindow.hh" #include "mainwindow.hh"
MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent) MainWindow::MainWindow(module_qt_window_s *qt_window, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, qt_window->reg, this); qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, qt_window->reg, this);
...@@ -13,14 +13,13 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent) ...@@ -13,14 +13,13 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent)
} }
void void
MainWindow::closeMpv(bool *exited) noexcept MainWindow::closeMpv() noexcept
{ {
emit emitCloseMpv(exited); emit emitCloseMpv();
} }
void void
MainWindow::__closeMpv(bool *exited) MainWindow::__closeMpv()
{ {
delete centralWidget(); delete this;
*exited = true;
} }
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(struct module_qt_window_s *qt_window, QWidget *parent = nullptr); explicit MainWindow(module_qt_window_s *qt_window, QWidget *parent = nullptr);
public slots: public slots:
inline void updateWindowTitle(QString str) noexcept { setWindowTitle(str); } inline void updateWindowTitle(QString str) noexcept { setWindowTitle(str); }
signals: signals:
void emitCloseMpv(bool *); void emitCloseMpv();
private slots: private slots:
void __closeMpv(bool *); void __closeMpv();
public: public:
void closeMpv(bool *) noexcept; void closeMpv() noexcept;
}; };
#include "mpvwidget_interface.hh" #include "mpvwidget_interface.hh"
#include "mainwindow.hh"
#include <QApplication> #include <QApplication>
#include <QEventLoop>
#include "mainwindow.hh"
void * void *
___create_mpv_widget(struct poller_thread_arg *arg) ___create_mpv_widget(void *arg)
{ {
lkt_thread_set_name("lektord/qt-win"); lkt_thread_set_name("lektord/qt-win");
/* Unsage reinterpret cast, but isok */ /* Unsage reinterpret cast, but isok */
struct module_qt_window_s *qt_window = reinterpret_cast<struct module_qt_window_s *>(arg->args); module_qt_window_s *qt_window = reinterpret_cast<module_qt_window_s *>(arg);
int argc = 0; int argc = 0;
QApplication a(argc, nullptr); QApplication app(argc, nullptr);
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
qt_window->main_window = new MainWindow(qt_window); qt_window->main_window = new MainWindow(qt_window);
qt_window->main_window->show(); qt_window->main_window->show();
a.exec(); app.exec();
return nullptr; return nullptr;
} }
...@@ -65,8 +68,6 @@ ___module_qt_window_toggle_pause(struct module_qt_window_s *win) ...@@ -65,8 +68,6 @@ ___module_qt_window_toggle_pause(struct module_qt_window_s *win)
bool bool
___module_qt_window_close(struct module_qt_window_s *win) ___module_qt_window_close(struct module_qt_window_s *win)
{ {
bool exited = false; win->main_window->closeMpv();
win->main_window->closeMpv(&exited);
delete win->main_window;
return true; return true;
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <lektor/common.h> #include <lektor/common.h>
#include "../module_qt_window.hh" #include "../module_qt_window.hh"
void *___create_mpv_widget(struct poller_thread_arg *arg); void *___create_mpv_widget(void *arg);
bool ___module_qt_window_get_elapsed(struct module_qt_window_s *, int *); bool ___module_qt_window_get_elapsed(struct module_qt_window_s *, int *);
bool ___module_qt_window_get_duration(struct module_qt_window_s *, int *); bool ___module_qt_window_get_duration(struct module_qt_window_s *, int *);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter