Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect two QQuickWidgets

Connect two QQuickWidgets

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 478 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ProgSysP Offline
    ProgSysP Offline
    ProgSys
    wrote on last edited by
    #1

    I have two separate QQuickWidgets and I am trying to connect them but nothing seams to work:

    C++:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->quickViewA->setSource(QUrl::fromLocalFile("a.qml"));
        ui->quickViewB->setSource(QUrl::fromLocalFile("b.qml"));
    
        //QML connect
        //try 1
        connect(  ui->quickViewA, SIGNAL( foo(  QVariant )),  ui->quickViewB, SLOT( foo( QVariant )));
        //try 2
        connect(  ui->quickViewA, SIGNAL( foo(  int )),  ui->quickViewB, SLOT( foo( int )));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    a.qml:

    import QtQuick 2.4
    
    Rectangle { 
    	id: root
    	signal foo(int id)
    	MouseArea {
    		anchors.fill: parent
    		onClicked: { 
    			root.foo(42)
    		}
    	}
    	color:"red"
    }
    

    b.qml:

    import QtQuick 2.4
    
    Rectangle { 
    	function foo(id){ console.log(id) }
    }
    

    In both cases it can't find the signal.
    I am doing something wrong or is it just not possible to do it this way?

    1 Reply Last reply
    0
    • ProgSysP Offline
      ProgSysP Offline
      ProgSys
      wrote on last edited by
      #2

      Well got it to work:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          ui->quickViewA->setSource(QUrl::fromLocalFile("a.qml"));
          ui->quickViewB->setSource(QUrl::fromLocalFile("b.qml"));
      
          QObject* a = (QObject*)(ui->quickViewA->rootObject());
          QObject* b = (QObject*)(ui->quickViewB->rootObject());
      
          connect(  a, SIGNAL( foo(  QVariant )),  b, SLOT( foo( QVariant )));
      }
      

      a.qml:

      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"
      }
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved