Display is not cleared after closing QT5 application window

1.7k views Asked by At

I have cross-compiled Qt5.4.8 using yocto for TexasInstruments DRA7XX-EVM board. Below are my configuration options.

QT_CONFIG_FLAGS = \
-rpath \
-pkg-config \
-opengl es2 \
-no-accessibility \
-dbus \
-no-directfb \
-evdev \
-make examples \
-compile-examples \
-no-fontconfig \
-freetype \
-no-iconv \
-icu \
-system-libjpeg \
-system-libpng \
-make libs \
-eglfs \    
-kms \    
-linuxfb \
-no-mitshm \
-no-mtdev -no-nis -openssl-linked -no-openvg -qt-pcre -pulseaudio -release -no-sm -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-sql-tds -nomake tests -make tools -no-tslib -libudev -widgets -no-xcb -no-xcursor -no-xfixes -no-xinerama -no-xinput -no-xinput2 -no-xkb -no-xkbcommon -no-xrandr -no-xrender -no-xshape -no-xsync -no-xvideo -system-zlib \
-no-wayland \
-force-pkg-config \

I have exported below variables on my target shell:

export QT_QPA_PLATFORM=linuxfb

export QT_QPA_GENERIC_PLUGINS=evdevtouch,evdevmouse,evdevkeyboard

export QT_QPA_EVDEV_KEYBOARD_PARAMETERS=grab=1

and I run my application: $./myapplication

The window is shown properly on the screen. But when I exit the application the screen is not cleared. Please check my configuration options and tell me if any changes need to be done. And also some solution regarding clearing the framebuffer after the window is closed.

3

There are 3 answers

0
merge On

I had the same problem and added the following signal handler, defined in main() for example as: CleanExit cleanExit;, to solve this:

#include <csignal>

struct CleanExit{
        CleanExit() {
                signal(SIGINT, &CleanExit::exitQt);
                signal(SIGTERM, &CleanExit::exitQt);
        }

        static void exitQt(int sig) {
                QCoreApplication::exit(0);
        }
};
0
Bluefalcon On

I solved this issue by using qAddPostRoutine() to add a routine that clears the frame buffer on exit.

The following is the clear function:

//Used on exit to clear the fb
static void fbclear()
{
   char dev[256] = "/dev/fb";
   struct fb_var_screeninfo var_info;
   int fd = open(dev, O_RDWR);
   int line_size;
   int buffer_size;
   void *buffer = NULL;
   if (fd < 0) {
       printf("failed to open %s display device\n", dev);
       return;
   }
   //get display size
   ioctl (fd, FBIOGET_VSCREENINFO, &var_info);
   line_size = var_info.xres * var_info.bits_per_pixel / 8;
   buffer_size = line_size * var_info.yres;
   //malloc buffer and set to 0
   buffer = malloc(buffer_size);
   memset(buffer, 0, buffer_size);
   //write zeros to display
   write(fd, buffer, buffer_size);
   free(buffer);
   close(fd);
   return;
}

I then added the following to my main():

qAddPostRoutine(fbclear);
0
GregTheMadMonk On

Ok I know this is an old question but for but for anyone struggling with this I might've found the solution.

If after quitting linuxfb Qt application your screen is not reset and doesn't receive input, it means that Qt for some reason failed to reset it itself, and you have to do the same thing manually. For that, qfbvthandler.cpp is useful to look at, but here's what I did:

  1. Before initializing any Qt objects back up current tty's mode:
int k_mode = -1; // back up variable
...
int tfd = open("/dev/tty", O_RDWR);
if (tfd == -1) throw runtime_error("Cannot open TTY");
ioctl(tfd, KDGKBMODE, &k_mode);
if (k_mode == -1) throw runtime_error("Cannot recieve KDBMODE");
close(tfd);

  1. After QApplication::quit() do the job Qt failed to do:
int tfd = open("/dev/tty", O_RDWR);
if (tfd == -1) throw runtime_error("Cannot open TTY");
ioctl(tfd, KDSETMODE, KD_TEXT); // return to text mode from graphics mode
ioctl(tfd, 0x4b51, 0); // 0x4b51=KDKBMUTE, from qfbvthandler.cpp
ioctl(tfd, KDSKBMODE, k_mode); // set keyboard mode back
k_mode = -1;
const auto blink_on = "\033[9;15]\033[?33h\033[?25h\033[?0c"; // from qfbvthandler.cpp
write(tfd, blink_on, strlen(blink_on) + 1); // enable blanking and cursor
close(tfd);