Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. image not getting displayed in cross compiled qt in raspberry pi without x11
Forum Update on Tuesday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amruz
    wrote on 21 Jul 2017, 09:10 last edited by amruz
    #1

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

    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

    J 1 Reply Last reply 21 Jul 2017, 10:48
    0
    • A amruz
      21 Jul 2017, 09:10

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

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 21 Jul 2017, 10:48 last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 21 Jul 2017, 11:00
      2
      • J jsulm
        21 Jul 2017, 10:48

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

        A Offline
        A Offline
        amruz
        wrote on 21 Jul 2017, 11:00 last edited by
        #3

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

        J 1 Reply Last reply 21 Jul 2017, 11:02
        0
        • A amruz
          21 Jul 2017, 11:00

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 21 Jul 2017, 11:02 last edited by jsulm
          #4

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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 21 Jul 2017, 11:14
          2
          • J jsulm
            21 Jul 2017, 11:02

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

            A Offline
            A Offline
            amruz
            wrote on 21 Jul 2017, 11:14 last edited by
            #5

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

            J 1 Reply Last reply 21 Jul 2017, 11:16
            0
            • A amruz
              21 Jul 2017, 11:14

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 21 Jul 2017, 11:16 last edited by
              #6

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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              1/6

              21 Jul 2017, 09:10

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved