I have an embedded linux application running directly on the linux framebuffer (no x-Windows). We now have to physically rotate the display 180 degrees. How do I get my Qt application to rotate so it doesn't appear upside down? I saw reference to using the following option:
-platform linuxfb:fb=/dev/fb0:rotation:180
However, the rotation option seems to be ignored.
Using Qt 5.9.2 on Ubuntu server 16.04.6
You could handle it on application level. With QML thats easy, but with QWidgets the best I could come up with is to render the Widget on a QGraphicsScene and rotate it like this:
#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsView *view = new QGraphicsView();
view->setGeometry(w.geometry());
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scene->addWidget(&w);
view->setScene(scene);
view->show();
view->rotate(180);
//w.show();
return a.exec();
}
It seems a bit glitchy, but you could give it a try.
Also I think the correct syntax is -platform linuxfb:fb=/dev/fb0:rotation=180 note the = instead of :
Edit: but that did not make a difference for me either.
Related
I want to create a GUI toolkit for my desktop environment (because neither gtk nor qt don't fit to my needs) but I don't know how to start. I don't want a cross-platform or display-server independent library, theming options, configurable icons etc. just a few basic widgets for making wayland clients. (widgets like button, entry, label, window and images... and I want to use CSD if it's important)
My problem is that I can't understand how graphics work in wayland (in X you only need to create a window and use XDrawLine etc. right?) also I don't know how to write a graphical toolkit. Can you give me some articles or recommendations on how can I do this?
The easiest way to create a wayland client is to use the wayland-client library. Basically, it abstracts the wire format.
example:
#include <stdio.h>
#include <wayland-client.h>
int main(void)
{
struct wl_display *display = wl_display_connect(NULL);
if (display) {
printf("Connected!\n");
} else {
printf("Error connecting ;(\n");
return 1;
}
wl_display_disconnect(display);
return 0;
}
I'm trying to add a new system call to linux -5.9.8 for this I've been following this tutorial from a prev question and this one and this from a guide they are both really similar and everything does work as intended BUT to get the system call to show with dmesg we get to compile the following code after boot up:
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#define __NR_identity 440
long identity_syscall(void)
{
return syscall(__NR_identity);
}
int main(int argc, char *argv[])
{
long activity;
activity = identity_syscall();
if(activity < 0)
{
perror("Sorry. Your system call appears to have failed.");
}
else
{
printf("Congratulations! Your system call is functional. Run the command dmesg in the terminal and find out!\n");
}
return 0;
}
This code does in fact add the message to dmesg but it does it after boot up and I need to run the code everytime, how should I go to actually make my system call appear on the boot up screen and not later, what file should I edit to make it happen?
If the goal is to merely display some sort of message at system startup time, you don't need a system call but rather a kernel module statically linked or dynamically loaded.
In the file where you define the system call, you can add an "init" routine which will be called by the kernel at startup. To make it, the kernel build chain uses "__init" section identifier to gather all the initialization entry points into a dedicated section. Then, in the boot procedure, all the functions from this section are called. You can try something like the following from your example (I didn't tried it !):
#include <linux/kernel.h>
#include <linux/syscalls.h>
SYSCALL_DEFINE0(identity)
{
printk("I am Jihan Jasper Al-rashid.\n");
return 0;
}
void __init identity_entry(void)
{
printk("Boot message from identity\n");
}
I was working on Windows with this program and was ok..
When im running it on linux (using QT creator, same on windows) window show and hide immediately.
The program is to big to paste it all, this is my main.cpp code
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
What should it be?
If there is no fatal exception that exits the app then the event loop (a.exec()) is quitting due to some event served. So, the visibility is not enough to conclude why your app is quitting on Linux.
So I am aware of the following link: Problem accessing camera when using Boost thread on OSX
But my issue is that I cannot display windows when using openCV from within a boost thread. I.e:
int main(int argc, char* argv[]) {
CvCapture* cvInputObj = cvCaptureFromCAM((CV_CAP_ANY)); //OSX
assert( cvInputObj != NULL ); //term on fail here
cVision vision(cvInputObj); //Define cVision thread obj
boost::thread cVision_thd(boost::bind(&cVision::Run, &vision));
cVision_thd.join();
std::cout<<"System Going Down..."<<std::endl;
}
In cVision I do a bunch of openCv calls such as for ex:
cvNamedWindow("MONITOR", CV_WINDOW_AUTOSIZE);
cvShowImage("MONITOR", imCur);
etcetc, where imCur is extracted out as such:
imCur = cvQueryFrame(input);
This exact code works perfectly in Linux. I have originally tried this with a custom makefile. That did not work. After this I tried with CMAKE. Still the same result. And still works fine in linux. I installed openCV using homebrew.
Create the window in the main thread, and then pass the name of the window as a parameter to cVision constructor.
Remember, the window is created with: cvNamedWindow("MONITOR", CV_WINDOW_AUTOSIZE);
I have an executable module created by third party. I would like to "inject" my code (kind of watchdog running in separate thread) into this process.
So far there are two possible ways - one is to run my code as executable and dynamically load a proess on top of it (seems to be very hard and tricky) or to make my code a shared object, load it via LD_PRELOAD and initialize from some static variable constructor.
Are there more convenient ways to do this ?
My OS are Linux x86 and Solaris-SPARC.
Update: If possible, I'd like not to patch the process, but load my code dynamicaly.
Sounds like you're looking for InjectSo. There's a Powerpoint presentation that explains how it works. I haven't gotten around to trying it out yet.
Hotpatch should do this for you. It is more capable than injectso.
Rob Kennedy told you about InjectSo - that's probably what you need.
Beware that the introduction of a thread into a non-threaded process would be fraught with synchronization issues. The problems are less serious if the application is already threaded, but even so, the application may object to a thread that it doesn't know about.
I have not used the mentioned InjectSo but it is a noteworthy information.
If you are looking for alternatives here is a simple way to inject your code:
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
int main()
{
struct passwd* pswd = getpwuid(1000);
if(pswd)
printf("%s\n", pswd->pw_name);
return 0;
}
gcc test.c -o test
#define _GNU_SOURCE
#include <dlfcn.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdlib.h>
#include <stdio.h>
static char* hocus = "hocus pocus";
struct passwd *getpwuid(uid_t uid)
{
static struct passwd *(*orig_getpwuid)(uid_t uid);
if(!orig_getpwuid) {
orig_getpwuid = (struct passwd* (*)(uid_t))dlsym(RTLD_NEXT, "getpwuid");
}
struct passwd* original_passwd = (*orig_getpwuid)(uid);
if(original_passwd) {
original_passwd->pw_name = hocus;
}
// your code here
return original_passwd;
}
gcc inject.c -shared -o libinject.so
run with LD_LIBRARY_PATH=. LD_PRELOAD=libinject.so ./test
Should say hocus pocus. You can override arbitrary libc functions, like printf, snprintf - just find what is that module using.
In the "your code here" you can start arbitrary threads, watchdogs etc.