image not getting displayed in cross compiled qt in raspberry pi without x11



  • i cross compiled qt without x11 in raspberry pi following
    https://wiki.qt.io/RaspberryPi2EGLFS

    Now i am trying to place the following items in the screen without x11

    1.buttons
    2.images

    1. virtual keyboard

    i am using widget application and i have managed to place a button in the screen which on click event displays a message box. But when i try to display image it is not getting displayed in my raspberry screen.
    This is my code

    mainwindow.h

    #ifndef MAINWINDOW_H

    #define MAINWINDOW_H

    #include<qobject.h>
    #include <QMainWindow>
    #include <QPushButton>
    #include<QLineEdit>
    #include <QHBoxLayout>
    #include<qlabel.h>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow

    {
    Q_OBJECT

    public:

    explicit MainWindow(QWidget *parent = 0);

    private slots:

    void handleButton();

    void m_buttonClicked();

    private:

    QPushButton *m_button;

    QLineEdit *m_textbox;

    QHBoxLayout *layout;

    QWidget *window;

    QLabel * label;

    };

    #endif // MAINWINDOW_H

    mainwindow.cpp

    #include "mainwindow.h"

    #include <QCoreApplication>
    #include <QMessageBox>
    #include <QDebug>
    using namespace std;

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    // window = new QWidget;
    //set CentralWidget(window);
    layout = new QHBoxLayout( this );
    m_textbox = new QLineEdit ( this );
    // Create the button, make "this" the parent
    m_button = new QPushButton("My Button",this);
    // set size and location of the button
    m_button->setGeometry(QRect(QPoint(300, 200),
    QSize(200, 50)));

    //create the text box
    layout->addWidget(m_textbox);
    m_textbox->setGeometry(100,200,90,25);
    
    //create a image viewer
    QString url = R"(krishna.jpg)";
    QPixmap img(url);
    QLabel *label = new QLabel(this);
    label->setGeometry(200,300,100,50);
    label->resize(this->width(),300);
    label->setPixmap(img);
    // Connect button signal to appropriate slot
    connect(m_button, SIGNAL (clicked()), this, SLOT (m_buttonClicked()));
    

    }

    void MainWindow::m_buttonClicked()
    {
    m_textbox = new QLineEdit;
    m_textbox->setPlaceholderText("Placeholder Text");
    m_textbox->setFocus();
    QMessageBox::information( this, "Information", "Just clicked Ui PushButton" );
    }

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {

    QApplication app(argc, argv);
    MainWindow mainWindow;
    mainWindow.showMaximized();
    return app.exec();
    

    }

    can anyone help me with this. I am pretty new to this. And also i don’t know how to place virtual keyboard in the screen. any guidelines in that is also appreciated.

    Thanks in advance


  • Moderators

    @amruz said in image not getting displayed in cross compiled qt in raspberry pi without x11:

    QString url = R"(krishna.jpg)";

    Are you aware that you're using a relative path? That means the system will look for krishna.jpg in the current directory what ever it will be at that time. Where did you put the picture on your device? Either use an absolute path or construct a path at runtime relative to the location of your executable (see http://doc.qt.io/qt-5/qstandardpaths.html). As alternative you can use Qt resources.



  • @jsulm i placed the image in the build folder of the project .


  • Moderators

    @amruz Then how do you start your app? And what is the working directory then? You should avoid using relative paths to avoid such issues...
    Also you do not have any kind of error checking in your code.



  • @jsulm thanks a lot. it worked. I used path relative to run time..
    If possible can you please provide me some guidelines in placing virtual keyboard in pi using qt?


  • Moderators

    @amruz Not sure what exactly you want to know. Did you read http://doc.qt.io/qt-5/qtvirtualkeyboard-index.html ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.