Skip to content

Commit

Permalink
try to fix crash on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed Dec 16, 2019
1 parent b46afb5 commit 1f154c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ int main(int argc, char *argv[])
g_palette = &palette;

VMainWindow w(&guard);
app.setWindow(&w);
QString style = palette.fetchQtStyleSheet();
if (!style.isEmpty()) {
app.setStyleSheet(style);
Expand All @@ -276,8 +277,8 @@ int main(int argc, char *argv[])

w.kickOffStartUpTimer(filePaths);

app.setWindow(&w);
int ret = app.exec();
app.setWindow(nullptr);
if (ret == RESTART_EXIT_CODE) {
// Ask to restart VNote.
guard.exit();
Expand Down
5 changes: 3 additions & 2 deletions src/vapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
VApplication::VApplication(int &argc, char **argv)
: QApplication(argc, argv)
{
connect(this, &QApplication::applicationStateChanged, this, &VApplication::onApplicationStateChanged);
connect(this, &QApplication::applicationStateChanged,
this, &VApplication::onApplicationStateChanged);
}

void VApplication::onApplicationStateChanged(Qt::ApplicationState state)
{
Q_UNUSED(state);
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
if(state == Qt::ApplicationActive) {
if(state == Qt::ApplicationActive && this->window) {
this->window->show();
// Need to call raise() in macOS.
this->window->raise();
Expand Down
4 changes: 2 additions & 2 deletions src/vapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public slots:
void onApplicationStateChanged(Qt::ApplicationState state);

private:
VMainWindow *window;
VMainWindow *window = nullptr;
};

#endif // VAPPLICATION_H
#endif // VAPPLICATION_H

0 comments on commit 1f154c0

Please sign in to comment.