user23494417
user23494417

Reputation: 1

QT multiple windows display issue in touchscreen for yocto beaglebone black

I am doing yocto project for beaglebone black board with MACHINE NAME='beaglebone' using the meta-ti layer. I need to run a qt application on startup in a touchscreen. I am using X11 rendering.

The BBB is booting with qt application on startup. In my application I have designed multiple indexes in a stackedwidget in the mainwindow. The mainwindow contains an icon which is basically a login page. If you click that icon, it displays a dialog box which contains 2 icons. If you click either of the icons it will display a keyboard and by entering the correct password you can go to the corresponding page (It is also one of the stackedwidgets in the mainwindow).

This application is working fine on my desktop. But when I boot this into the touchscreen, I am able to login only once. After that if I go back to my homescreen and try to login again, my whole window gets freezed.

I have replicated this issue in this demo application.

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
dialog = new Dialog(this);
connect(dialog, &Dialog::engmodeenter, this, &MainWindow::Engmodeclicked);
connect(dialog, &Dialog::advmodeenter, this, &MainWindow::Advmodeclicked);
}

MainWindow::~MainWindow()
{
 delete ui;
}

void MainWindow::on_login_clicked()
{
QPoint mainWindowCenter = this->geometry().center();
QPoint dialogTopLeft = mainWindowCenter - QPoint(dialog->width() / 2, dialog->height() / 2);
dialog->move(dialogTopLeft);

dialog->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint  | Qt::MSWindowsFixedSizeDialogHint);
dialog->setWindowModality(Qt::WindowModal);
dialog->show();
}

void MainWindow::Engmodeclicked()
{
ui->stackedWidget->setCurrentIndex(1);
}

void MainWindow::Advmodeclicked()
{
ui->stackedWidget->setCurrentIndex(2);
}

void MainWindow::on_pushButton_4_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
}


void MainWindow::on_pushButton_5_clicked()
{
     ui->stackedWidget->setCurrentIndex(0);
}

dialog.cpp

#include "dialog.h"
#include "ui_dialog.h"
#include <QDebug>
#include <QMessageBox>

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(0);
// Connect Keyboard numbers
 connect(ui->btn_1, SIGNAL(clicked()), this, SLOT(onLetterButtonClicked()));
 connect(ui->btn_2, SIGNAL(clicked()), this, SLOT(onLetterButtonClicked()));

 updateLetterButtons();

 connect(ui->btn_11, SIGNAL(clicked()), this, SLOT(onLetterButtonClicked1()));
 connect(ui->btn_22, SIGNAL(clicked()), this, SLOT(onLetterButtonClicked1()));

 updateLetterButtons_1();

}

Dialog::~Dialog()
{
delete ui;
}

void Dialog::on_pushButton_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
}

void Dialog::on_pushButton_2_clicked()
{
ui->stackedWidget->setCurrentIndex(2);
}


void Dialog::on_back_clicked()
{
this->close();
}


void Dialog::on_back_2_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}


void Dialog::on_back_3_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}


void Dialog::on_enter_clicked()
{
QString password = ui->lineEdit->text();

if (password == "1") {
   qDebug() << "Correct password :)";
   emit engmodeenter();
    //this->close();

} else {
    qDebug() << "Incorrect password! in Eng mode....";
    QMessageBox::warning(this, "Warning", "Please Enter correct Password...");

}
ui->lineEdit->clear();
accept();
ui->stackedWidget->setCurrentIndex(0);
}


void Dialog::on_enter_2_clicked()
{
QString password = ui->lineEdit_2->text();
if(password == "2"){
    qDebug() <<"Correct password :)";
    emit advmodeenter();

}else{
    qDebug() << "Incorrect password :(";
    QMessageBox::warning(this, "Warning", "Please Enter correcrt password");

}
ui->lineEdit_2->clear();
accept();
ui->stackedWidget->setCurrentIndex(0);
}

void Dialog::updateLetterButtons()
{
qDebug() << "Updating Letter Buttons...";

// Update the appearance of all letter buttons based on Caps Lock state
foreach (QPushButton *letterButton, findChildren<QPushButton*>()) {
    if (letterButton->text().length() == 1) {
QChar character = letterButton->text().at(0);
    }
}
}

void Dialog::onLetterButtonClicked()
{
QPushButton *clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
    QString letter = clickedButton->text();
    qDebug() << "Letter Button Clicked: " << letter;
updateLetterButtons();
    }
}

void Dialog::updateLetterButtons_1()
{
qDebug() << "Updating Letter Buttons...";


foreach (QPushButton *letterButton, findChildren<QPushButton*>()) {
    if (letterButton->text().length() == 1) {
        QChar character = letterButton->text().at(0); 


    }
}
}

void Dialog::onLetterButtonClicked1()
{
QPushButton *clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
    QString letter = clickedButton->text();
    qDebug() << "Letter Button Clicked: " << letter;
updateLetterButtons_1();
    }
}

main.cpp

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow mw;
mw.show();
return a.exec();
}

mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>589</width>
    <height>414</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QStackedWidget" name="stackedWidget">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>30</y>
      <width>461</width>
      <height>291</height>
     </rect>
    </property>
    <property name="currentIndex">
     <number>0</number>
    </property>
    <widget class="QWidget" name="page">
     <widget class="QPushButton" name="login">
      <property name="geometry">
       <rect>
    <x>200</x>
    <y>250</y>
    <width>89</width>
    <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>login</string>
      </property>
     </widget>
     <widget class="QLabel" name="label">
      <property name="geometry">
       <rect>
    <x>210</x>
    <y>70</y>
    <width>91</width>
    <height>31</height>
       </rect>
      </property>
      <property name="text">
       <string>Home Page</string>
      </property>
     </widget>
    </widget>
    <widget class="QWidget" name="page_2">
     <widget class="QPushButton" name="pushButton_4">
      <property name="geometry">
       <rect>
    <x>190</x>
    <y>250</y>
    <width>89</width>
    <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>back</string>
      </property>
     </widget>
     <widget class="QLabel" name="label_2">
      <property name="geometry">
       <rect>
    <x>200</x>
    <y>150</y>
    <width>67</width>
    <height>17</height>
       </rect>
      </property>
      <property name="text">
       <string>Page 1</string>
      </property>
     </widget>
    </widget>
    <widget class="QWidget" name="page_3">
     <widget class="QPushButton" name="pushButton_5">
      <property name="geometry">
       <rect>
    <x>180</x>
    <y>240</y>
    <width>89</width>
    <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>back</string>
      </property>
     </widget>
     <widget class="QLabel" name="label_3">
      <property name="geometry">
       <rect>
    <x>190</x>
    <y>130</y>
    <width>67</width>
    <height>17</height>
       </rect>
      </property>
      <property name="text">
       <string>Page 2</string>
      </property>
     </widget>
    </widget>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

dialog.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>673</width>
    <height>352</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <widget class="QStackedWidget" name="stackedWidget">
   <property name="geometry">
    <rect>
     <x>90</x>
     <y>60</y>
     <width>511</width>
     <height>241</height>
    </rect>
   </property>
   <property name="currentIndex">
    <number>1</number>
   </property>
   <widget class="QWidget" name="page">
    <widget class="QPushButton" name="pushButton">
     <property name="geometry">
      <rect>
       <x>60</x>
       <y>70</y>
       <width>101</width>
       <height>71</height>
      </rect>
     </property>
     <property name="text">
      <string>Page 1</string>
     </property>
    </widget>
    <widget class="QPushButton" name="pushButton_2">
     <property name="geometry">
      <rect>
       <x>320</x>
       <y>70</y>
       <width>101</width>
       <height>71</height>
      </rect>
     </property>
     <property name="text">
      <string>Page 2</string>
     </property>
    </widget>
    <widget class="QPushButton" name="back">
     <property name="geometry">
      <rect>
       <x>210</x>
       <y>170</y>
       <width>89</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>back</string>
     </property>
    </widget>
   </widget>
   <widget class="QWidget" name="page_2">
    <widget class="QLineEdit" name="lineEdit">
     <property name="geometry">
      <rect>
       <x>170</x>
       <y>90</y>
       <width>181</width>
       <height>25</height>
      </rect>
     </property>
    </widget>
    <widget class="QPushButton" name="enter">
     <property name="geometry">
      <rect>
       <x>210</x>
       <y>170</y>
       <width>89</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>Enter</string>
     </property>
    </widget>
    <widget class="QPushButton" name="back_2">
     <property name="geometry">
      <rect>
       <x>20</x>
       <y>170</y>
       <width>89</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>back</string>
     </property>
    </widget>
    <widget class="QPushButton" name="btn_1">
     <property name="geometry">
      <rect>
       <x>170</x>
       <y>130</y>
       <width>51</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>1</string>
     </property>
    </widget>
    <widget class="QPushButton" name="btn_2">
     <property name="geometry">
      <rect>
       <x>300</x>
       <y>130</y>
       <width>51</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>2</string>
     </property>
    </widget>
    <widget class="QLabel" name="label">
     <property name="geometry">
      <rect>
       <x>220</x>
       <y>30</y>
       <width>101</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Page1 login</string>
     </property>
    </widget>
   </widget>
   <widget class="QWidget" name="page_3">
    <widget class="QPushButton" name="enter_2">
     <property name="geometry">
      <rect>
       <x>230</x>
       <y>170</y>
       <width>89</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>Enter</string>
     </property>
    </widget>
    <widget class="QLineEdit" name="lineEdit_2">
     <property name="geometry">
      <rect>
       <x>190</x>
       <y>90</y>
       <width>181</width>
       <height>25</height>
      </rect>
     </property>
    </widget>
    <widget class="QPushButton" name="back_3">
     <property name="geometry">
      <rect>
       <x>20</x>
       <y>170</y>
       <width>89</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>back</string>
     </property>
    </widget>
    <widget class="QPushButton" name="btn_11">
     <property name="geometry">
      <rect>
       <x>190</x>
       <y>130</y>
       <width>51</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>1</string>
     </property>
    </widget>
    <widget class="QPushButton" name="btn_22">
     <property name="geometry">
      <rect>
       <x>320</x>
       <y>130</y>
       <width>51</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
      <string>2</string>
     </property>
    </widget>
    <widget class="QLabel" name="label_2">
     <property name="geometry">
      <rect>
       <x>240</x>
       <y>40</y>
       <width>91</width>
       <height>21</height>
      </rect>
     </property>
     <property name="text">
      <string>Page 2 login</string>
     </property>
    </widget>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "dialog.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();


private slots:
    void on_login_clicked();
    void Engmodeclicked();
    void Advmodeclicked();

    void on_pushButton_4_clicked();

    void on_pushButton_5_clicked();

private:
    Ui::MainWindow *ui;
    Dialog *dialog;

};
#endif // MAINWINDOW_H

dialog.h

#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = nullptr);
    ~Dialog();

signals:
    void engmodeenter();
    void advmodeenter();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_back_clicked();

    void on_back_2_clicked();

    void on_back_3_clicked();

    void on_enter_clicked();

    void on_enter_2_clicked();

    void updateLetterButtons();

    void onLetterButtonClicked();

    void updateLetterButtons_1();

    void onLetterButtonClicked1();


private:
    Ui::Dialog *ui;

};

#endif // DIALOG_H

demo.pro

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

QT +=widgets
TARGET = demo
TEMPLATE = app

SOURCES += \
    dialog.cpp \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    dialog.h \
    mainwindow.h

FORMS += \
    dialog.ui \
    mainwindow.ui

Upvotes: 0

Views: 60

Answers (0)

Related Questions