解决线程无法析构的问题
parent
52734adda8
commit
f504480050
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindowClass</class>
|
||||
<widget class="QMainWindow" name="MainWindowClass">
|
||||
<widget class="QWidget" name="MainWindowClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
|
@ -10,19 +10,9 @@
|
|||
<height>722</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 10pt "Segoe UI, Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
|
@ -60,7 +50,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -12,14 +12,13 @@
|
|||
|
||||
FRAMELESSHELPER_USE_NAMESPACE
|
||||
|
||||
CentralWidget::CentralWidget(QWidget* parent) : QMainWindow(parent)
|
||||
CentralWidget::CentralWidget(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
NavigationBarWidget* navigationBarWidget = new NavigationBarWidget(this);
|
||||
ui.gridLayout->addWidget(navigationBarWidget, 0, 0, 1, 1, Qt::AlignTop | Qt::AlignHCenter);
|
||||
QObject::connect(navigationBarWidget->tabs, &QtMaterialTabs::currentChanged, ui.stackedWidget, &QStackedWidget::setCurrentIndex);
|
||||
QObject::connect(ui.stackedWidget, &QStackedWidget::currentChanged,
|
||||
ui.rendererWidget, &Renderer::RendererWidget::currentTabChanged);
|
||||
QObject::connect(ui.stackedWidget, &QStackedWidget::currentChanged, ui.rendererWidget, &Renderer::RendererWidget::currentTabChanged);
|
||||
}
|
||||
|
||||
CentralWidget::~CentralWidget()
|
||||
|
@ -40,7 +39,7 @@ MainWindow::MainWindow(QWidget* parent, const Qt::WindowFlags flags)
|
|||
m_titleBar->chromePalette()->setTitleBarActiveBackgroundColor(QColor(0, 0, 0, 0));
|
||||
m_titleBar->chromePalette()->setTitleBarInactiveBackgroundColor(QColor(0, 0, 0, 0));
|
||||
|
||||
m_central_widget = new CentralWidget();
|
||||
m_central_widget = new CentralWidget(this);
|
||||
|
||||
setMenuWidget(m_titleBar);
|
||||
setCentralWidget(m_central_widget);
|
||||
|
@ -73,4 +72,5 @@ void MainWindow::closeEvent(QCloseEvent* event)
|
|||
|
||||
if (result != QMessageBox::Yes)
|
||||
event->ignore();*/
|
||||
qDebug() << "closeEvent";
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
|
|||
class StandardTitleBar;
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
class CentralWidget : public QMainWindow
|
||||
class CentralWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -117,7 +117,7 @@ QRectF calcBoundingRect(const QPainterPath& path, const std::vector<BaseStyle>&
|
|||
Renderer::ElementRenderer::ElementRenderer()
|
||||
{
|
||||
surface.create();
|
||||
thread = std::jthread([&] {
|
||||
thread = std::jthread([&](std::stop_token stop) {
|
||||
QOpenGLContext context;
|
||||
context.create();
|
||||
context.makeCurrent(&surface);
|
||||
|
@ -131,7 +131,7 @@ Renderer::ElementRenderer::ElementRenderer()
|
|||
|
||||
initialized = true;
|
||||
|
||||
while (true)
|
||||
while (!stop.stop_requested())
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(drawMutex);
|
||||
draw.wait(lock, [&] {return needDraw; });
|
||||
|
|
|
@ -18,7 +18,7 @@ Renderer::VirtualTextureManager::VirtualTextureManager(GladGLContext* glMain)
|
|||
surface.create();
|
||||
mainContext->doneCurrent();
|
||||
|
||||
thread = std::jthread([&] {
|
||||
thread = std::jthread([&](std::stop_token stop) {
|
||||
QOpenGLContext context;
|
||||
context.setFormat(mainContext->format());
|
||||
context.setShareContext(mainContext);
|
||||
|
@ -67,7 +67,7 @@ Renderer::VirtualTextureManager::VirtualTextureManager(GladGLContext* glMain)
|
|||
GLuint pageLoadTimeQuery;
|
||||
gl->GenQueries(1, &pageLoadTimeQuery);
|
||||
|
||||
while (true)
|
||||
while (!stop.stop_requested())
|
||||
{
|
||||
if (needUpdate)
|
||||
{
|
||||
|
@ -85,6 +85,7 @@ Renderer::VirtualTextureManager::VirtualTextureManager(GladGLContext* glMain)
|
|||
//qDebug() << duration;
|
||||
pageLoadDuration += duration;
|
||||
}
|
||||
std::this_thread::yield();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue