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