EGLFS QML Screen not rotated - linux

I have Debian Bullseye, Intel Celeron J1800 with integrated graphics. Qt from Debian version 5.12.5
Trying to rotate screen to portrait mode.
QT_QPA_EGLFS_ROTATION=90 /opt/app/bin/app
But window just resized, scaled up about 120%.
My code
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.addImportPath("qrc:/");
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
And QML
ApplicationWindow {
id: window
visible: true
flags: Qt.FramelessWindowHint
StackView { ... }
}
QWebEngineView and widgets works well

Seems works
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QQuickWidget>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QApplication app(argc, argv);
const QUrl url(QStringLiteral("qrc:/main.qml"));
QQuickWidget *w = new QQuickWidget;
w->resize(400,300);
w->setResizeMode(QQuickWidget::SizeRootObjectToView );
w->engine()->addImportPath("qrc:/");
w->setSource(url);
w->showFullScreen();
return app.exec();
}
and qml
Rectangle {
id: window
visible: true
StackView { ... }
}

Related

How to fix QDialog transparent background afterimage issue in qt embedded (QT4.7.3)?

I am using embedded system and I'm testing transparent QWS server where is my Qt4.7.3.
I faced the afterimage in the QDialog when moving cursor in test program which as the QWS client, but it didn't happen in the QMainWindow which in QWS server program.
Can anyone help me to fix the issue?
There is the issue
Here is test program source code.
#include "mainwindow.h"
#include <QApplication>
#include<QWSServer>
#include <QDialog>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "qscreenlinuxfb_qws.h"
#include "qscreendriverfactory_qws.h"
#include <errno.h>
extern "C" {
extern int Test();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog w;
QWSServer::setBackground(QColor(0,0,0,0));
QWSServer::setCursorVisible(false);
w.setStyleSheet("background-color:transparent;");
w.show();
return a.exec();
}
OK I found the issue. In QT source code.
src\gui\embedded\qscreen_qws.cpp
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
}
to
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
QPixmap temp = QPixmap(blendSize);
temp.fill(Qt::transparent);
**blendbuffer = temp.toImage();
}

Qt serial communication using UART RS232C

I want to connect qt and a device using UART cable (RS232C) in linux.
I´m writing code, making ui and operating, but it does not work.
I want to connect when i click some button(ui) device turn on and connect.
Also i want to make a function that if i enter some command device will recognize and execute.
Below is my code , someone help me please.
<mainwindow.cpp>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSerialPort/QSerialPort>
#include <QMessageBox>
#include <QObject>
#include <QIODevice>
#include <QDebug>
QSerialPort serial;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QSerialPort*port=new QSerialPort();
port->setPortName("/dev/ttyUSB0");
port->setBaudRate(QSerialPort::Baud19200);
port->setDataBits(QSerialPort::Data8);
port->setParity(QSerialPort::NoParity);
port->setStopBits(QSerialPort::OneStop);
port->setFlowControl(QSerialPort::NoFlowControl);
port->open(QIODevice::ReadWrite);
ui->setupUi(this);
serial = new QSerialPort(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_connect_clicked()
{
port=new QSerialPort();
QObject::connect(port,SIGNAL(readyRead()),this,
SLOT(on_pushButton_connect_clicked()));
if(!port->open(QIODevice::ReadWrite)){
QMessageBox::information(this, tr("connect"),
"serialcommunication start");
}
else
{
QMessageBox::critical(this, tr("fail"), serial-
>errorString());
}
}
void MainWindow::on_pushButton_disconnect_clicked()
{
port->close();
QMessageBox::information(this, tr("disconnect"), "serial
communication end");
}
<mainwindow.h>
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSerialPort/QSerialPort>
#include <QMessageBox>
#include <QIODevice>
#include <QDebug>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
QSerialPort*serial; //plus
QSerialPort*port;
QWidget*main_widget;
void readData();
~MainWindow();
private slots:
void on_pushButton_connect_clicked();
void on_pushButton_disconnect_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
<main.cpp>
#include "mainwindow.h"
#include <QApplication>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <QMessageBox>
#include <QIODevice>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
foreach(const QSerialPortInfo
&info,QSerialPortInfo::availablePorts()){
QSerialPort serial;
serial.setPort(info);
if (serial.open(QIODevice::ReadWrite))
serial.close();
}
MainWindow w;
w.show();
return a.exec();
}
First of all it is not guaranteed that your device will be always connected to /dev/ttyUSB0 so you'l better search for your device by QSerialPortInfo with parameter
QString manufacturer() const or quint16 productIdentifier() const or QString serialNumber() const.
Also you are creating too many QSerialPort and don't handle it. Create just one.
Here is sample code:
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QSerialPort;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
//! Receives all the data from serial port
void readSerialData();
void on_pushButton_connect_clicked();
void on_pushButton_disconnect_clicked();
private:
Ui::MainWindow *ui;
QSerialPort *mSerialPort;
};
#endif // MAINWINDOW_H
Next check your Your product manufacturer or serial number and set here.
Also you need separate handler for received data like I created readSerialData
mainwindows.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QMessageBox>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
mSerialPort{new QSerialPort}
{
ui->setupUi(this);
mSerialPort->setBaudRate(QSerialPort::Baud19200);
mSerialPort->setDataBits(QSerialPort::Data8);
mSerialPort->setParity(QSerialPort::NoParity);
mSerialPort->setStopBits(QSerialPort::OneStop);
mSerialPort->setFlowControl(QSerialPort::NoFlowControl);
connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(readSerialData()));
}
MainWindow::~MainWindow()
{
delete mSerialPort;
delete ui;
}
void MainWindow::readSerialData()
{
QByteArray lTmpBA;
lTmpBA = mSerialPort->readAll();
qDebug() << "Received data: " << lTmpBA;
}
void MainWindow::on_pushButton_connect_clicked()
{
foreach(QSerialPortInfo item, QSerialPortInfo::availablePorts()) {
if (item.manufacturer() == "Your product") { //past your manufacturer here
mSerialPort->setPort(item);
if(!mSerialPort->open(QIODevice::ReadWrite)){
QMessageBox::information(this, tr("connect"),
"serialcommunication start");
} else {
QMessageBox::critical(this, tr("fail"), mSerialPort->errorString());
}
} else {
qDebug() << "No connected device found";
}
}
}
void MainWindow::on_pushButton_disconnect_clicked()
{
mSerialPort->close();
}
latter if you want to send some data to your UART device just implemente slot and call method:
mSerialPort->write("Some command");

qt thread file not found

fatal error: 'thread' file not found
this is main.cpp.
#include <QApplication>
#include <QMainWindow>
#include <thread>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.show();
return a.exec();
}
this is pro file.
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = empty
TEMPLATE = app
DEFINES += CC_TARGET_QT5
CONFIG += c++11
SOURCES += main.cpp
a strange question. why ?

Sending structure through sockets in Qt

I am writing a client server application to transfer data in linux platform. I am developing a GUI application for client side in QT.I am just a beginner in QT and please help in transferring a structure from server side to client side.
The server side code written for non-GUI environment
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#pragma pack(1)
struct basestruct
{
int element1;
int element2;
};
#pragma pack(0)
struct basestruct newstruct;
int main(int argc, char *argv[])
{
int listenfd = 0, connfd = 0,n=0;
struct sockaddr_in serv_addr;
char sendBuff[1025];
listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
memset(sendBuff, '0', sizeof(sendBuff));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(5000);
bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
listen(listenfd, 10);
while(1)
{
connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
newstruct.element1=1;
newstruct.element2=2;
if((n=send(connfd,(void *)&newstruct,sizeof(struct basestruct),0))<0)
perror("Write error");
printf("sent items :%d \n",n);
close(connfd);
sleep(1);
}}`
The client side code written in QT
#include "dialog.h"
#include "ui_dialog.h"
#include <QString>
#include <QDebug>
#include <QTextStream>
#include <QByteRef>
struct basestruct
{
int element1;
int element2;
};
basestruct newstruct;
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->pushButton->setText("Connect");
ui->pushButton_2->setText("Ok");
ui->pushButton_3->setText("Close");
ui->pushButton_4->setText("Disconnect");
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::Read()
{
socket->waitForReadyRead(-1);
QByteArray byteArray;
byteArray=socket->readAll();
deserialize(byteArray);
qDebug()<<socket->readAll();
qDebug()<<"Read contents";
socket->flush();
}
void Dialog::on_pushButton_clicked()
{
socket=new QTcpSocket(this);
socket->connectToHost("127.0.0.1",5000);
qDebug()<<"Connected";
Read();
}
void Dialog::on_pushButton_4_clicked()
{
socket->close();
qDebug()<<"Disconnected";
}
void Dialog::deserialize(const QByteArray& byteArray)
{
QDataStream stream(byteArray);
stream.setVersion(QDataStream::Qt_4_0);
qDebug()<<"size received" <<byteArray.size();
stream >> newstruct.element1
>> newstruct.element2;
qDebug()<<"Element1"<<newstruct.element1<<"Element2"<<newstruct.element2;
}
When I receive the structure and print using qDebug() I am getting some garbage values. Kindly help me and point where I have gone wrong.Is there any easy alternative method to transfer structure in QT without serialising (similar to Non-GUI applications).
Thanks in advance
The Endianness problem can be overcome by specifying the Endianess as:
stream.setByteOrder(QDataStream::LittleEndian);
in the deserialise function after declaring Qdatastream.

Wrong size in Qt widget + widget updage issue

Here is a pruned version of a problem I have using QT/linux. The program runs, but the size of the displayed widget is wrong (the contents, frame + labels, does not fit).
I understood that the size of a windows should be computed fron its contents (children). Why is that not happening properly here?
So the first question is, of course why this is happening.
The real program actually updates the contents of the widget at run-time. I have tried to simulate that behavior by the insertion of the main_window->show() (commented //SHOW1). If this first show() call is made, then the second show() does not show the new contents the widget. I have tried with update without success...
#include <QApplication>
#include <QtCore>
#include <QMainWindow>
#include <QTabWidget>
#include <QWidget>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <stdlib.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow* main_window = new(QMainWindow);
main_window->setObjectName("main_window");
main_window->resize(800, 600);
main_window->setWindowTitle("Hello");
QTabWidget* node_tab_widget = new QTabWidget(main_window);
// node_tab_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
// node_tab_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));
node_tab_widget->resize(500, 400);
QWidget* w= new QWidget(node_tab_widget);
node_tab_widget->addTab(w, "TAB");
//main_window->show(); //SHOW1
QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
QVBoxLayout* group_layout = new QVBoxLayout;
group_widget->setLayout(group_layout);
group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));
group_layout->addWidget((QLabel*)new QLabel("here2"));
// group_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
main_window->update();
main_window->show();
return app.exec();
}
I don't really understand what is the result you expect, can be something like what you get from this code:
#include <QApplication>
#include <QtCore>
#include <QMainWindow>
#include <QTabWidget>
#include <QWidget>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <stdlib.h>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow* main_window = new(QMainWindow);
main_window->setObjectName("main_window");
main_window->resize(800, 600);
main_window->setWindowTitle("Hello");
QTabWidget* node_tab_widget = new QTabWidget();
node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));
node_tab_widget->resize(500, 400);
QWidget* w= new QWidget();
node_tab_widget->addTab(w, "TAB");
QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
QVBoxLayout* group_layout = new QVBoxLayout;
group_widget->setLayout(group_layout);
group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));
group_layout->addWidget((QLabel*)new QLabel("here2"));
QVBoxLayout* gl = new QVBoxLayout;
gl->addWidget(group_widget);
main_window->setCentralWidget(node_tab_widget);
main_window->show();
return app.exec();
}
which add the QTabWidget node_tab_widget as central widget, with a tab TAB.
The tab contain the QGroupBox GROUPNAME with the two labels (vertical aligned)

Resources