void MainWindow::updateView() { QSurfaceFormat format; format.setDepthBufferSize(16); format.setStencilBufferSize(8); if (m_transparent) format.setAlphaBufferSize(8); if (m_checkboxMultiSample->isChecked()) format.setSamples(4); State state = m_radioView->isChecked() ? UseWindow : UseWidget; if (m_format == format && m_state == state) return; m_format = format; m_state = state; QString text = m_currentRootObject ? m_currentRootObject->property("currentText").toString() : QStringLiteral("Hello Qt"); QUrl source("qrc:qquickviewcomparison/test.qml"); if (m_state == UseWindow) { QQuickView *quickView = new QQuickView; // m_transparent is not supported here since many systems have problems with semi-transparent child windows quickView->setFormat(m_format); quickView->setResizeMode(QQuickView::SizeRootObjectToView); connect(quickView, &QQuickView::statusChanged, this, &MainWindow::onStatusChangedView); connect(quickView, &QQuickView::sceneGraphError, this, &MainWindow::onSceneGraphError); quickView->setSource(source); m_currentRootObject = quickView->rootObject(); switchTo(QWidget::createWindowContainer(quickView)); } else if (m_state == UseWidget) { QQuickWidget *quickWidget = new QQuickWidget; if (m_transparent) { quickWidget->setClearColor(Qt::transparent); quickWidget->setAttribute(Qt::WA_TranslucentBackground); } quickWidget->setFormat(m_format); quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); connect(quickWidget, &QQuickWidget::statusChanged, this, &MainWindow::onStatusChangedWidget); connect(quickWidget, &QQuickWidget::sceneGraphError, this, &MainWindow::onSceneGraphError); quickWidget->setSource(source); m_currentRootObject = quickWidget->rootObject(); switchTo(quickWidget); } if (m_currentRootObject) { m_currentRootObject->setProperty("currentText", text); m_currentRootObject->setProperty("multisample", m_checkboxMultiSample->isChecked()); m_currentRootObject->setProperty("translucency", m_transparent); } m_overlayLabel->raise(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //criar os temporizadores like a Thread timer = new QTimer(this); //evento do timeout do timer - quando estourar faça o método atualizar connect(timer,SIGNAL(timeout()),this,SLOT(atualizarDados())); //Dados do QML /*QQuickView *view = new QQuickView(); QWidget *container = QWidget::createWindowContainer(view, this); container->setMinimumSize(500, 200); container->setMaximumSize(500, 200); container->setFocusPolicy(Qt::TabFocus); view->setSource(QUrl("qrc:/qml/dashboard.qml")); ui->verticalLayout->addWidget(container); */ QQuickWidget *view = new QQuickWidget(); view->setResizeMode(QQuickWidget::SizeRootObjectToView); //connect(quickWidget, &QQuickWidget::statusChanged, this, &MainWindow::onStatusChangedWidget); //connect(quickWidget, &QQuickWidget::sceneGraphError, this, &MainWindow::onSceneGraphError); //view->setMinimumSize(500, 200); //view->setMaximumSize(500, 200); view->setSource(QUrl("qrc:/qml/dashboard.qml")); ui->verticalLayout->addWidget(view); QObject *item = view->rootObject(); velocidade = item->findChild<QObject*>("velocidade"); temperatura = item->findChild<QObject*>("temperatura"); rpm = item->findChild<QObject*>("rpm"); borboleta = item->findChild<QObject*>("borboleta"); // Criar um agente para descoberta de dispositivos discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); connect(discoveryAgent, SIGNAL(finished()), this, SLOT(finalizarBuscaDispositivos()) ); connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(buscarServidor())); connect(ui->pushButtonConectar,SIGNAL(clicked(bool)),this,SLOT(conectarServidor())); //Configurações para a conexão com o servidor socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); connect( socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()) ); connect( socket, SIGNAL(connected()), this, SLOT(onBluetoothConnected()) ); connect( socket, SIGNAL(disconnected()), this, SLOT(onBluetoothDisconnected()) ); connect( socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(onBluetoothError(QBluetoothSocket::SocketError)) ); }