Important: Please read the Qt Code of Conduct -

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

  • i cross compiled qt without x11 in raspberry pi following

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

    3. 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


    #ifndef MAINWINDOW_H

    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QPushButton>
    #include <QHBoxLayout>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow



    explicit MainWindow(QWidget *parent = 0);

    private slots:

    void handleButton();

    void m_buttonClicked();


    QPushButton *m_button;

    QLineEdit *m_textbox;

    QHBoxLayout *layout;

    QWidget *window;

    QLabel * label;


    #endif // MAINWINDOW_H


    #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
    //create a image viewer
    QString url = R"(krishna.jpg)";
    QPixmap img(url);
    QLabel *label = new QLabel(this);
    // 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");
    QMessageBox::information( this, "Information", "Just clicked Ui PushButton" );


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

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

    QApplication app(argc, argv);
    MainWindow mainWindow;
    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

  • Lifetime Qt Champion

    @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 As alternative you can use Qt resources.

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

  • Lifetime Qt Champion

    @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?

  • Lifetime Qt Champion

    @amruz Not sure what exactly you want to know. Did you read ?

Log in to reply