<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Connect two QQuickWidgets]]></title><description><![CDATA[<p dir="auto">I have two separate QQuickWidgets and I am trying to connect them but nothing seams to work:</p>
<p dir="auto">C++:</p>
<pre><code class="language-c++">#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
    ui-&gt;quickViewA-&gt;setSource(QUrl::fromLocalFile("a.qml"));
    ui-&gt;quickViewB-&gt;setSource(QUrl::fromLocalFile("b.qml"));

    //QML connect
    //try 1
    connect(  ui-&gt;quickViewA, SIGNAL( foo(  QVariant )),  ui-&gt;quickViewB, SLOT( foo( QVariant )));
    //try 2
    connect(  ui-&gt;quickViewA, SIGNAL( foo(  int )),  ui-&gt;quickViewB, SLOT( foo( int )));
}

MainWindow::~MainWindow()
{
    delete ui;
}
</code></pre>
<p dir="auto">a.qml:</p>
<pre><code>import QtQuick 2.4

Rectangle { 
	id: root
	signal foo(int id)
	MouseArea {
		anchors.fill: parent
		onClicked: { 
			root.foo(42)
		}
	}
	color:"red"
}
</code></pre>
<p dir="auto">b.qml:</p>
<pre><code>import QtQuick 2.4

Rectangle { 
	function foo(id){ console.log(id) }
}
</code></pre>
<p dir="auto">In both cases it can't find the signal.<br />
I am doing something wrong or is it just not possible to do it this way?</p>
]]></description><link>https://forum.qt.io/topic/71942/connect-two-qquickwidgets</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 12:02:08 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/71942.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Oct 2016 17:00:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Connect two QQuickWidgets on Tue, 04 Oct 2016 17:40:17 GMT]]></title><description><![CDATA[<p dir="auto">Well got it to work:</p>
<pre><code>MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
    ui-&gt;quickViewA-&gt;setSource(QUrl::fromLocalFile("a.qml"));
    ui-&gt;quickViewB-&gt;setSource(QUrl::fromLocalFile("b.qml"));

    QObject* a = (QObject*)(ui-&gt;quickViewA-&gt;rootObject());
    QObject* b = (QObject*)(ui-&gt;quickViewB-&gt;rootObject());

    connect(  a, SIGNAL( foo(  QVariant )),  b, SLOT( foo( QVariant )));
}
</code></pre>
<p dir="auto">a.qml:</p>
<pre><code>import QtQuick 2.4

Rectangle { 
	id: root
	signal foo(var id) // int changed to var
	MouseArea {
		anchors.fill: parent
		onClicked: { 
			root.foo(42)
			console.log(42) 
		}
	}
	color:"red"
}
</code></pre>
]]></description><link>https://forum.qt.io/post/351874</link><guid isPermaLink="true">https://forum.qt.io/post/351874</guid><dc:creator><![CDATA[ProgSys]]></dc:creator><pubDate>Tue, 04 Oct 2016 17:40:17 GMT</pubDate></item></channel></rss>