PDA

View Full Version : QCoreApplication::postEvent: Unexpected null receiver while running application



karpt
25th September 2015, 22:43
Hi all,

Upon running my QT application, I am seeing the following Unexpected null receiver error. What is this error?

QCoreApplication::postEvent: Unexpected null receiver
file:///home/andy/Qt/5.3/gcc_64/qml/QtQuick/Controls/ApplicationWindow.qml: Conflicting properties 'visible' and 'visibility' for Window 'root'

The error also mentions something about conflicting 'visible' and 'visibility' properties in ApplicationWindow.qml

Can someone please explain what could be going on?

Thanks.

anda_skoa
26th September 2015, 10:06
Looks like you accidentally forgot to post the code of your ApplicationWindow using QML file.

Cheers,
_

karpt
28th September 2015, 16:24
Sorry about that. Here is the code from ApplicationWindow.qml.

/************************************************** **************************
.....
**
** $QT_END_LICENSE$
**
************************************************** **************************/

import QtQuick.Window 2.1
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
import QtQuick.Controls.Private 1.0

/*!
\qmltype ApplicationWindow
\since 5.1
\inqmlmodule QtQuick.Controls
\ingroup applicationwindow
\brief Provides a top-level application window.

\image applicationwindow.png

ApplicationWindow is a \l Window that adds convenience for positioning items,
such as \l MenuBar, \l ToolBar, and \l StatusBar in a platform independent
manner.

\code
ApplicationWindow {
id: window
visible: true

menuBar: MenuBar {
Menu { MenuItem {...} }
Menu { MenuItem {...} }
}

toolBar: ToolBar {
RowLayout {
anchors.fill: parent
ToolButton {...}
}
}

TabView {
id: myContent
anchors.fill: parent
...
}
}
\endcode

\note By default, an ApplicationWindow is not visible.

The \l{Qt Quick Controls - Gallery} example is a good starting
point to explore this type.
*/

Window {
id: root

/*!
\qmlproperty MenuBar ApplicationWindow::menuBar

This property holds the \l MenuBar.

By default, this value is not set.
*/
property MenuBar menuBar: null

/*!
\qmlproperty Item ApplicationWindow::toolBar

This property holds the toolbar \l Item.

It can be set to any Item type, but is generally used with \l ToolBar.

By default, this value is not set. When you set the toolbar item, it will
be anchored automatically into the application window.
*/
property Item toolBar

/*!
\qmlproperty Item ApplicationWindow::statusBar

This property holds the status bar \l Item.

It can be set to any Item type, but is generally used with \l StatusBar.

By default, this value is not set. When you set the status bar item, it
will be anchored automatically into the application window.
*/
property Item statusBar

// The below documentation was supposed to be written as a grouped property, but qdoc would
// not render it correctly due to a bug (https://bugreports.qt-project.org/browse/QTBUG-34206)
/*!
\qmlproperty ContentItem ApplicationWindow::contentItem

This group holds the size constraints of the content item. This is the area between the
\l ToolBar and the \l StatusBar.
The \l ApplicationWindow will use this as input when calculating the effective size
constraints of the actual window.
It holds these 6 properties for describing the minimum, implicit and maximum sizes:
\table
\header \li Grouped property \li Description
\row \li contentItem.minimumWidth \li The minimum width of the content item.
\row \li contentItem.minimumHeight \li The minimum height of the content item.
\row \li contentItem.implicitWidth \li The implicit width of the content item.
\row \li contentItem.implicitHeight \li The implicit height of the content item.
\row \li contentItem.maximumWidth \li The maximum width of the content item.
\row \li contentItem.maximumHeight \li The maximum height of the content item.
\endtable
*/
property alias contentItem : contentArea

/*! \internal */
property real __topBottomMargins: contentArea.y + statusBarArea.height
/*! \internal
There is a similar macro QWINDOWSIZE_MAX in qwindow_p.h that is used to limit the
range of QWindow::maximum{Width,Height}
However, in case we have a very big number (> 2^31) conversion will fail, and it will be
converted to 0, resulting in that we will call setMaximumWidth(0)....
We therefore need to enforce the limit at a level where we are still operating on
floating point values.
*/
readonly property real __qwindowsize_max: (1 << 24) - 1

/*! \internal */
property real __width: 0
Binding {
target: root
property: "__width"
when: root.minimumWidth <= root.maximumWidth
value: Math.max(Math.min(root.maximumWidth, contentArea.implicitWidth), root.minimumWidth)
}
/*! \internal */
property real __height: 0
Binding {
target: root
property: "__height"
when: root.minimumHeight <= root.maximumHeight
value: Math.max(Math.min(root.maximumHeight, contentArea.implicitHeight), root.minimumHeight)
}
width: contentArea.__noImplicitWidthGiven ? 0 : __width
height: contentArea.__noImplicitHeightGiven ? 0 : __height

minimumWidth: contentArea.__noMinimumWidthGiven ? 0 : contentArea.minimumWidth
minimumHeight: contentArea.__noMinimumHeightGiven ? 0 : (contentArea.minimumHeight + __topBottomMargins)

maximumWidth: Math.min(__qwindowsize_max, contentArea.maximumWidth)
maximumHeight: Math.min(__qwindowsize_max, contentArea.maximumHeight + __topBottomMargins)
onToolBarChanged: { if (toolBar) { toolBar.parent = toolBarArea } }

onStatusBarChanged: { if (statusBar) { statusBar.parent = statusBarArea } }

onVisibleChanged: { if (visible && menuBar) { menuBar.__parentWindow = root } }

/*! \internal */
default property alias data: contentArea.data

color: SystemPaletteSingleton.window(true)

flags: Qt.Window | Qt.WindowFullscreenButtonHint |
Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowMinMaxButtonsHint |
Qt.WindowCloseButtonHint | Qt.WindowFullscreenButtonHint
// QTBUG-35049: Windows is removing features we didn't ask for, even though Qt::CustomizeWindowHint is not set
// Otherwise Qt.Window | Qt.WindowFullscreenButtonHint would be enough

Item {
id: backgroundItem
anchors.fill: parent

Keys.forwardTo: menuBar ? [menuBar.__contentItem] : []

ContentItem {
id: contentArea
anchors.top: toolBarArea.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: statusBarArea.top
}

Item {
id: toolBarArea
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
implicitHeight: childrenRect.height
height: visibleChildren.length > 0 ? implicitHeight: 0
}

Item {
id: statusBarArea
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
implicitHeight: childrenRect.height
height: visibleChildren.length > 0 ? implicitHeight: 0
}

onVisibleChanged: if (visible && menuBar) menuBar.__parentWindow = root

states: State {
name: "hasMenuBar"
when: menuBar && !menuBar.__isNative

ParentChange {
target: menuBar.__contentItem
parent: backgroundItem
}

PropertyChanges {
target: menuBar.__contentItem
x: 0
y: 0
width: backgroundItem.width
}

AnchorChanges {
target: toolBarArea
anchors.top: menuBar.__contentItem.bottom
}
}
}
}

Added after 8 minutes:

I also wanted to include the code from qquickwindowmodule.cpp which contains reference to the error message

/************************************************** **************************
**...........
** $QT_END_LICENSE$
**
************************************************** **************************/

#include "qquickwindowmodule_p.h"
#include "qquickscreen_p.h"
#include "qquickview_p.h"
#include <QtQuick/QQuickWindow>
#include <QtCore/QCoreApplication>
#include <QtQml/QQmlEngine>

#include <private/qguiapplication_p.h>
#include <private/qqmlengine_p.h>
#include <qpa/qplatformintegration.h>

QT_BEGIN_NAMESPACE

class QQuickWindowQmlImpl : public QQuickWindow, public QQmlParserStatus
{
Q_INTERFACES(QQmlParserStatus)
Q_OBJECT

Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged)

public:
QQuickWindowQmlImpl(QWindow *parent = 0)
: QQuickWindow(parent)
, m_complete(false)
, m_visible(isVisible())
, m_visibility(AutomaticVisibility)
{
connect(this, &QWindow::visibleChanged, this, &QQuickWindowQmlImpl::visibleChanged);
connect(this, &QWindow::visibilityChanged, this, &QQuickWindowQmlImpl::visibilityChanged);
}

void setVisible(bool visible) {
if (!m_complete)
m_visible = visible;
else if (!transientParent() || transientParent()->isVisible())
QQuickWindow::setVisible(visible);
}

void setVisibility(Visibility visibility)
{
if (!m_complete)
m_visibility = visibility;
else
QQuickWindow::setVisibility(visibility);
}

Q_SIGNALS:
void visibleChanged(bool arg);
void visibilityChanged(QWindow::Visibility visibility);

protected:
void classBegin() {
QQmlEngine* e = qmlEngine(this);
//Give QQuickView behavior when created from QML with QQmlApplicationEngine
if (QCoreApplication::instance()->property("__qml_using_qqmlapplicationengine") == QVariant(true)) {
if (e && !e->incubationController())
e->setIncubationController(incubationController());
}
Q_ASSERT(e);
{
QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(e);
QV4::Scope scope(v4);
QV4::ScopedObject v(scope, new (v4->memoryManager) QQuickRootItemMarker(e, this));
rootItemMarker = v;
}
}

void componentComplete() {
m_complete = true;
if (transientParent() && !transientParent()->isVisible()) {
connect(transientParent(), &QQuickWindow::visibleChanged, this,
&QQuickWindowQmlImpl::setWindowVisibility, Qt::QueuedConnection);
} else {
setWindowVisibility();
}
}

private Q_SLOTS:
void setWindowVisibility()
{
if (transientParent() && !transientParent()->isVisible())
return;

if (sender()) {
disconnect(transientParent(), &QWindow::visibleChanged, this,
&QQuickWindowQmlImpl::setWindowVisibility);
}

// We have deferred window creation until we have the full picture of what
// the user wanted in terms of window state, geometry, visibility, etc.

if ((m_visibility == Hidden && m_visible) || (m_visibility > AutomaticVisibility && !m_visible)) {
QQmlData *data = QQmlData::get(this);
Q_ASSERT(data && data->context);

QQmlError error;
error.setObject(this);

const QQmlContextData* urlContext = data->context;
while (urlContext && urlContext->url.isEmpty())
urlContext = urlContext->parent;
error.setUrl(urlContext ? urlContext->url : QUrl());

QString objectId = data->context->findObjectId(this);
if (!objectId.isEmpty())
error.setDescription(QCoreApplication::translate("QQuickWindowQmlImpl",
"Conflicting properties 'visible' and 'visibility' for Window '%1'").arg(objectId));
else
error.setDescription(QCoreApplication::translate("QQuickWindowQmlImpl",
"Conflicting properties 'visible' and 'visibility'"));

QQmlEnginePrivate::get(data->context->engine)->warning(error);
}

if (m_visibility == AutomaticVisibility) {
setWindowState(QGuiApplicationPrivate::platformInt egration()->defaultWindowState(flags()));
setVisible(m_visible);
} else {
setVisibility(m_visibility);
}
}

private:
bool m_complete;
bool m_visible;
Visibility m_visibility;
QV4::PersistentValue rootItemMarker;
};

void QQuickWindowModule::defineModule()
{
const char uri[] = "QtQuick.Window";

qmlRegisterType<QQuickWindow>(uri, 2, 0, "Window");
qmlRegisterRevision<QWindow,1>(uri, 2, 1);
qmlRegisterRevision<QWindow,2>(uri, 2, 2);
qmlRegisterRevision<QQuickWindow,1>(uri, 2, 1);//Type moved to a subclass, but also has new members
qmlRegisterRevision<QQuickWindow,2>(uri, 2, 2);
qmlRegisterType<QQuickWindowQmlImpl>(uri, 2, 1, "Window");
qmlRegisterUncreatableType<QQuickScreen>(uri, 2, 0, "Screen", QStringLiteral("Screen can only be used via the attached property."));
}

#include "qquickwindowmodule.moc"

QT_END_NAMESPACE

anda_skoa
28th September 2015, 17:11
And what of that is your code?
That looks like code shipped with Qt.

Cheers,
_

karpt
28th September 2015, 22:01
Thanks anda_skoa for your response. I was able to partially fix the error/warning. In my MainWindow.qml, the attribute "visible: true" was missing. As the default value of the visible attribute is false, this caused a conflict between visible: false and visibility: Maximum attributes. I added the attribute "visible: true" and the error regarding
"Conflicting properties 'visible' and 'visibility' for Window 'root'" disappeared. However, I still have the QCoreApplication:postEvent: Unexpected null receiver error which shows up as soon as the application launches. Unfortunately, the entire code is too huge to be included here and I am not sure which part of the code is triggering the postEvent() function. Any tips on how to go about finding the issue?


MainWindow.qml
--------
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import "."

ApplicationWindow {
id: mainWindow
visibility: "Maximized"
visible: true
width: 800
height: 600

title: "Main Window"
color: "whitesmoke"

property int msgBarHeight: 30

SplashScreen {
id: splash
visible: true
}
....

anda_skoa
29th September 2015, 10:04
Does that other error happen if you don't load the UI?

If it only appears when you load the UI, have you tried if it occurs when you minimize your main QML file?

In any case you can likely just ignore it.

Cheers,
_

karpt
29th September 2015, 16:59
The problem is fixed now. What was happening was that as soon as the application loaded, deleteLater() was being called on an object which was NULL initially. Upon placing the dleeteLater call inside a simple conditional, the error vanished.

Thanks a lot for your help anda_skoa.