vcl/qt5/QtFrame.cxx |   42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

New commits:
commit 4f60660bca1796184a4fe079b5ecdd562a36aa32
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Sep 1 17:50:19 2023 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Sep 1 20:29:02 2023 +0200

    qt: Set window title etc. in main thread
    
    These QWidget methods need to be called
    in the main thread.
    
    Otherwise, opening the Update dialog
    ("Help" -> "Check for Updates", enabled
    by `--enable-online-update` autogen switch)
    triggers asserts like the one below with
    a self-compiled Qt 6 development build
    (qtbase dev branch as of
    c802a9e987c9e38c01580f467eab92a651b3e033).
    
        ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to 
objects owned by a different thread. Current thread 0x0x7fff780160e0. Receiver 
'' (of type 'QtWidget') was created in thread 0x0x5555555fcd30", file 
/home/michi/development/git/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp, 
line 537
    
        Thread 40 "InitUpdateCheck" received signal SIGABRT, Aborted.
        [Switching to Thread 0x7fff7ffff6c0 (LWP 1516868)]
        __pthread_kill_implementation (threadid=<optimized out>, 
signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
        44      ./nptl/pthread_kill.c: No such file or directory.
        (gdb) bt
        #0  __pthread_kill_implementation (threadid=<optimized out>, 
signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
        #1  0x00007ffff78a815f in __pthread_kill_internal (signo=6, 
threadid=<optimized out>) at ./nptl/pthread_kill.c:78
        #2  0x00007ffff785a472 in __GI_raise (sig=sig@entry=6) at 
../sysdeps/posix/raise.c:26
        #3  0x00007ffff78444b2 in __GI_abort () at ./stdlib/abort.c:79
        #4  0x00007fffe32eb45a in qAbort() () at 
/home/michi/development/git/qt5/qtbase/src/corelib/global/qglobal.cpp:161
        #5  0x00007fffe32f9ee5 in qt_message_fatal(QtMsgType, 
QMessageLogContext const&, QString const&) (context=..., message=...) at 
/home/michi/development/git/qt5/qtbase/src/corelib/global/qlogging.cpp:2057
        #6  0x00007fffe32f620c in QMessageLogger::fatal(char const*, ...) const 
(this=0x7fff7fffb980, msg=0x7fffe37fd9a0 "ASSERT failure in %s: \"%s\", file 
%s, line %d")
            at 
/home/michi/development/git/qt5/qtbase/src/corelib/global/qlogging.cpp:938
        #7  0x00007fffe32e9d54 in qt_assert_x(char const*, char const*, char 
const*, int)
            (where=0x7fffe38131e9 "QCoreApplication::sendEvent", 
what=0x7fff78180110 "Cannot send events to objects owned by a different thread. 
Current thread 0x0x7fff780160e0. Receiver '' (of type 'QtWidget') was created 
in thread 0x0x5555555fcd30", file=0x7fffe3812e18 
"/home/michi/development/git/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp",
 line=537) at 
/home/michi/development/git/qt5/qtbase/src/corelib/global/qassert.cpp:77
        #8  0x00007fffe33a4d74 in 
QCoreApplicationPrivate::checkReceiverThread(QObject*) 
(receiver=0x55555d27d5d0) at 
/home/michi/development/git/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:537
        #9  0x00007fffe19a3a81 in QApplication::notify(QObject*, QEvent*) 
(this=0x5555555fcb80, receiver=0x55555d27d5d0, e=0x7fff7fffc0b0) at 
/home/michi/development/git/qt5/qtbase/src/widgets/kernel/qapplication.cpp:2584
        #10 0x00007fffe33a5ed0 in QCoreApplication::notifyInternal2(QObject*, 
QEvent*) (receiver=0x55555d27d5d0, event=0x7fff7fffc0b0) at 
/home/michi/development/git/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:1125
        #11 0x00007fffe33a6991 in QCoreApplication::sendEvent(QObject*, 
QEvent*) (receiver=0x55555d27d5d0, event=0x7fff7fffc0b0) at 
/home/michi/development/git/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:1559
        #12 0x00007fffe1a279b4 in QWidget::setWindowTitle(QString const&) 
(this=0x55555d27d5d0, title=...) at 
/home/michi/development/git/qt5/qtbase/src/widgets/kernel/qwidget.cpp:6119
        #13 0x00007fffe3c9d4c4 in QtFrame::SetTitle(rtl::OUString const&) 
(this=0x555555619d20, rTitle="Check for Updates") at 
/home/michi/development/git/libreoffice/vcl/qt6/../qt5/QtFrame.cxx:365
        #14 0x00007fffedd98d44 in vcl::Window::SetText(rtl::OUString const&) 
(this=0x7fff7803cd90, rStr="Check for Updates") at 
/home/michi/development/git/libreoffice/vcl/source/window/window.cxx:3042
        #15 0x00007fffedd311c9 in SystemWindow::SetText(rtl::OUString const&) 
(this=0x7fff7803cd90, rStr="Check for Updates") at 
/home/michi/development/git/libreoffice/vcl/source/window/syswin.cxx:1048
        #16 0x00007ffff048bd6b in VCLXWindow::setProperty(rtl::OUString const&, 
com::sun::star::uno::Any const&) (this=0x7fff7804ac00, PropertyName="Title", 
Value=uno::Any("string": "Check for Updates"))
            at 
/home/michi/development/git/libreoffice/toolkit/source/awt/vclxwindow.cxx:1515
        #17 0x00007ffff03e486d in VCLXContainer::setProperty(rtl::OUString 
const&, com::sun::star::uno::Any const&) (this=0x7fff7804ac00, 
PropertyName="Title", Value=uno::Any("string": "Check for Updates"))
            at 
/home/michi/development/git/libreoffice/toolkit/source/awt/vclxcontainer.cxx:260
        #18 0x00007ffff04dfa2c in VCLXDialog::setProperty(rtl::OUString const&, 
com::sun::star::uno::Any const&) (this=0x7fff7804ac00, PropertyName="Title", 
Value=uno::Any("string": "Check for Updates"))
            at 
/home/michi/development/git/libreoffice/toolkit/source/awt/vclxwindows.cxx:2364
        #19 0x00007ffff06a89b7 in UnoControl::ImplSetPeerProperty(rtl::OUString 
const&, com::sun::star::uno::Any const&) (this=0x7fff7803b4f0, 
rPropName="Title", rVal=uno::Any("string": "Check for Updates"))
            at 
/home/michi/development/git/libreoffice/toolkit/source/controls/unocontrol.cxx:288
        #20 0x00007ffff06aa701 in 
UnoControl::ImplModelPropertiesChanged(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyChangeEvent>
 const&) (this=0x7fff7803b4f0, rEvents=uno::Sequence of length 51 = {...})
            at 
/home/michi/development/git/libreoffice/toolkit/source/controls/unocontrol.cxx:649
        #21 0x00007ffff0531ae9 in 
ControlContainerBase::ImplModelPropertiesChanged(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyChangeEvent>
 const&) (this=0x7fff7803b4f0, rEvents=uno::Sequence of length 51 = {...})
            at 
/home/michi/development/git/libreoffice/toolkit/source/controls/controlmodelcontainerbase.cxx:1600
        #22 0x00007ffff0575a25 in 
UnoDialogControl::ImplModelPropertiesChanged(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyChangeEvent>
 const&) (this=0x7fff7803b4f0, rEvents=uno::Sequence of length 51 = {...})
            at 
/home/michi/development/git/libreoffice/toolkit/source/controls/dialogcontrol.cxx:651
        #23 0x00007ffff06a95f3 in 
UnoControl::propertiesChange(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyChangeEvent>
 const&) (this=0x7fff7803b4f0, rEvents=uno::Sequence of length 51 = {...})
            at 
/home/michi/development/git/libreoffice/toolkit/source/controls/unocontrol.cxx:431
        #24 0x00007ffff66bc4ee in 
cppu::OPropertySetHelper::firePropertiesChangeEvent(com::sun::star::uno::Sequence<rtl::OUString>
 const&, 
com::sun::star::uno::Reference<com::sun::star::beans::XPropertiesChangeListener>
 const&)
            (this=0x7fff78006170, rPropertyNames=uno::Sequence of length 51 = 
{...}, rListener=uno::Reference to (UnoDialogControl *) 0x7fff7803b540) at 
/home/michi/development/git/libreoffice/cppuhelper/source/propshlp.cxx:961
        #25 0x00007ffff06a8c6b in UnoControl::updateFromModel() 
(this=0x7fff7803b4f0) at 
/home/michi/development/git/libreoffice/toolkit/source/controls/unocontrol.cxx:320
        #26 0x00007ffff06aefc9 in 
UnoControl::createPeer(com::sun::star::uno::Reference<com::sun::star::awt::XToolkit>
 const&, com::sun::star::uno::Reference<com::sun::star::awt::XWindowPeer> 
const&)
            (this=0x7fff7803b4f0, rxToolkit=empty uno::Reference, 
rParentPeer=empty uno::Reference) at 
/home/michi/development/git/libreoffice/toolkit/source/controls/unocontrol.cxx:1325
        #27 0x00007ffff06c9905 in 
UnoControlContainer::createPeer(com::sun::star::uno::Reference<com::sun::star::awt::XToolkit>
 const&, com::sun::star::uno::Reference<com::sun::star::awt::XWindowPeer> 
const&)
            (this=0x7fff7803b4f0, rxToolkit=empty uno::Reference, rParent=empty 
uno::Reference) at 
/home/michi/development/git/libreoffice/toolkit/source/controls/unocontrolcontainer.cxx:727
        #28 0x00007ffff057336d in 
UnoDialogControl::createPeer(com::sun::star::uno::Reference<com::sun::star::awt::XToolkit>
 const&, com::sun::star::uno::Reference<com::sun::star::awt::XWindowPeer> 
const&)
            (this=0x7fff7803b4f0, rxToolkit=empty uno::Reference, 
rParentPeer=empty uno::Reference) at 
/home/michi/development/git/libreoffice/toolkit/source/controls/dialogcontrol.cxx:358
        #29 0x00007fffb7264e62 in UpdateHandler::createDialog() 
(this=0x7fff78003aa0) at 
/home/michi/development/git/libreoffice/extensions/source/update/check/updatehdl.cxx:1232
        #30 0x00007fffb725b0e1 in UpdateHandler::setVisible(bool) 
(this=0x7fff78003aa0, bVisible=true) at 
/home/michi/development/git/libreoffice/extensions/source/update/check/updatehdl.cxx:188
        #31 0x00007fffb7235887 in UpdateCheck::showDialog(bool) 
(this=0x7fff78000b90, forceCheck=true) at 
/home/michi/development/git/libreoffice/extensions/source/update/check/updatecheck.cxx:1171
        #32 0x00007fffb7255c5e in (anonymous 
namespace)::InitUpdateCheckJobThread::run() (this=0x55555d192690) at 
/home/michi/development/git/libreoffice/extensions/source/update/check/updatecheckjob.cxx:148
        #33 0x00007fffb723a74a in osl::threadFunc(void*) (param=0x55555d192690) 
at /home/michi/development/git/libreoffice/include/osl/thread.hxx:189
        #34 0x00007ffff7f3f693 in osl_thread_start_Impl(void*) 
(pData=0x55555d1a68b0) at 
/home/michi/development/git/libreoffice/sal/osl/unx/thread.cxx:237
        #35 0x00007ffff78a63ec in start_thread (arg=<optimized out>) at 
./nptl/pthread_create.c:444
        #36 0x00007ffff7926a1c in clone3 () at 
../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
    
    Change-Id: I6ccdee00fe26619f201459ebbe6c4d8cf8b57b45
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156426
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 179d4369a242..7cecebf2edf0 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -362,7 +362,10 @@ void QtFrame::SetWindowStateImpl(Qt::WindowStates eState)
 
 void QtFrame::SetTitle(const OUString& rTitle)
 {
-    m_pQWidget->window()->setWindowTitle(toQString(rTitle));
+    QtInstance* pSalInst(GetQtInstance());
+    assert(pSalInst);
+    pSalInst->RunInMainThread(
+        [this, rTitle]() { 
m_pQWidget->window()->setWindowTitle(toQString(rTitle)); });
 }
 
 void QtFrame::SetIcon(sal_uInt16 nIcon)
@@ -771,21 +774,25 @@ void QtFrame::SetAlwaysOnTop(bool bOnTop)
 
 void QtFrame::ToTop(SalFrameToTop nFlags)
 {
-    QWidget* const pWidget = asChild();
-    if (isWindow() && !(nFlags & SalFrameToTop::GrabFocusOnly))
-        pWidget->raise();
-    if ((nFlags & SalFrameToTop::RestoreWhenMin) || (nFlags & 
SalFrameToTop::ForegroundTask))
-    {
-        if (nFlags & SalFrameToTop::RestoreWhenMin)
-            pWidget->setWindowState(pWidget->windowState() & 
~Qt::WindowMinimized);
-        pWidget->activateWindow();
-    }
-    else if ((nFlags & SalFrameToTop::GrabFocus) || (nFlags & 
SalFrameToTop::GrabFocusOnly))
-    {
-        if (!(nFlags & SalFrameToTop::GrabFocusOnly))
+    QtInstance* pSalInst(GetQtInstance());
+    assert(pSalInst);
+    pSalInst->RunInMainThread([this, nFlags]() {
+        QWidget* const pWidget = asChild();
+        if (isWindow() && !(nFlags & SalFrameToTop::GrabFocusOnly))
+            pWidget->raise();
+        if ((nFlags & SalFrameToTop::RestoreWhenMin) || (nFlags & 
SalFrameToTop::ForegroundTask))
+        {
+            if (nFlags & SalFrameToTop::RestoreWhenMin)
+                pWidget->setWindowState(pWidget->windowState() & 
~Qt::WindowMinimized);
             pWidget->activateWindow();
-        pWidget->setFocus(Qt::OtherFocusReason);
-    }
+        }
+        else if ((nFlags & SalFrameToTop::GrabFocus) || (nFlags & 
SalFrameToTop::GrabFocusOnly))
+        {
+            if (!(nFlags & SalFrameToTop::GrabFocusOnly))
+                pWidget->activateWindow();
+            pWidget->setFocus(Qt::OtherFocusReason);
+        }
+    });
 }
 
 void QtFrame::SetPointer(PointerStyle ePointerStyle)
@@ -1365,7 +1372,10 @@ void QtFrame::registerDropTarget(QtDropTarget* 
pDropTarget)
 {
     assert(!m_pDropTarget);
     m_pDropTarget = pDropTarget;
-    m_pQWidget->setAcceptDrops(true);
+
+    QtInstance* pSalInst(GetQtInstance());
+    assert(pSalInst);
+    pSalInst->RunInMainThread([this]() { m_pQWidget->setAcceptDrops(true); });
 }
 
 void QtFrame::deregisterDropTarget(QtDropTarget const* pDropTarget)

Reply via email to