Search code examples
c++qt-creatormainwindow

How do I show Border Frame and Title Bar on MainWindow on Cross Compiled Application on an RPi3?


I am using QT Creator 4.5.2 based on 5.9.5 on Ubuntu 18 to build an application designed for a Raspberry Pi 3 running Stretch (cross compiled).

I can launch the application on the RPi3, but the MainWindow is full screen with no control buttons nor title bar and I can't seem to figure out how to change that. I have tried .show(), .showMaximized(), and .showFullScreen() all which produce the same results of a full screen application with no frame or control buttons.

What could I be missing here? For brevity, here are abbreviated versions of the main.cpp and mainwindow.h files:

Lines commented out are the .show functions that I've tried, all which seem to produce the same results. Note: there are no other references to any .show functions anywhere else in the code.

main.cpp:

#include "mainwindow.h"
#include <QDialog>
#include <QApplication>
#include <QScreen>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QScreen *screen = QGuiApplication::primaryScreen();
    QRect  screenGeometry = screen->geometry();
    int height = screenGeometry.height();
    int width = screenGeometry.width();
    MainWindow w;
    w.resize(height-100, width-100);
    w.setWindowFlags(Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint | Qt::WindowTitleHint);
    //w.show();
    //w.showMaximized();
    w.showFullScreen();
    return a.exec();
}

mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QObject>
#include <QCloseEvent>
#include <QDebug>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;

private slots:
    void closeApp();
};

#endif // MAINWINDOW_H

Solution

  • After some more hunting around, I found out it was two environment variables that had not been set up in QT Creator for the cross compiled RPI3. Here's how I solved it:

    In QT Creator I went to Mode Selector -> Projects. Then went to the Run Settings for my Raspberry Pi 3. In the Run Environment section I clicked FETCH DEVICE ENVIRONMENT. Then in the device environment I added the following two environment parameters according to a recommendation from https://forum.qt.io/topic/83929/qxcbconnection-could-not-connect-to-display/16:

    Variable Value

    DEVICE :0

    XAUTHORITY /home/pi/.Xauthority

    I start the program with a bash script on the RPi so the program can be launched using sudo (I'll be using pigpio as well) and added the command line parameter "-platform xcb" to the launcher script. Therefore in the Project Run settings I also changed the Run section of the Raspberry PI RUN project settings to /home/pi/Desktop/runapp.sh" to start the program using the launcher.

    Works perfectly now with all title bars, frames, and control buttons.