Why can't I embed a Xephyr instance into a Qt window? - c++

I am trying to get a Xephyr window opened within a Qt window of mine, but can't get it to work properly.
I am running a blank Qt application, for testing purpose, like this:
#include <QApplication>
#include <QWidget>
#include <iostream>
int main(int argc, char** argv) {
QApplication a(argc, argv);
QWidget window;
std::cout << window.winId() << std::endl;
window.resize(100, 100);
window.show();
return a.exec();
}
and compiling with g++ $(pkg-config --cflags --libs Qt5Widgets) test.cc
Then I get some window id after running the program. This time I got 104857606
Next, I use the Xephyr command Xephyr -parent 104857606 -screen 100x100 :1.
Here is the error I get when using it:
The XKEYBOARD keymap compiler (xkbcomp) reports:
> Warning: Could not resolve keysym XF86EmojiPicker
Errors from xkbcomp are not fatal to the X server
(EE)
Fatal server error:
(EE) X11 error
Error code: 8
Sequence number: 5
Major code: 1 Minor code: 0
Error value: 104857606
(EE)
I know this is an example of a BadMatch error, but I can't find out how to fix this. Even without the -screen 100x100, I can't get this program to work.
How can I get a Xephyr window into Qt if the -parent option doesn't work-- or how can I get this option to work?
I am using Arch Linux if that changes anything.

Related

Why won't this OpenGL program open a window?

I am currently trying to learn both C++ and OpenGL, and I am beginning with the following code example:
simple.cpp
#define GL_SILENCE_DEPRECATION
#include <GLUT/glut.h>
void init() {
// code to be inserted here
}
void mydisplay() {
glClear(GL_COLOR_BUFFER_BIT);
// need to fill in this part
// and add in shaders
}
int main(int argc, char** argv) {
glutCreateWindow("simple");
init();
glutDisplayFunc(mydisplay);
glutMainLoop();
}
It says here that this code can be compiled on MacOS using the following command:
gcc -Wno-deprecated-declarations -o hello hello.c -framework GLUT -framework OpenGL -framework Carbon
So I adapt the command in the following way:
gcc -Wno-deprecated-declarations -o simple simple.cpp -framework GLUT -framework OpenGL -framework Carbon
This seems to work and creates an executable called simple.
I am told that this code should generate a white square on a black background as follows:
However, when I try to run this file from the terminal using ./simple, the program runs continuously but nothing happens (that is, no window is generated at all), and so I have to terminate the program from the terminal.
Did I do something wrong here, or is this expected for the given code on MacOS?
EDIT1
To see what would happen, I tried to use the code presented in the aforementioned guide:
hello.c
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
void display()
{
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutDisplayFunc(display);
glutMainLoop();
}
As the guide says, this is "a simple OpenGL program that does nothing".
I compile it as follows:
gcc -Wno-deprecated-declarations -o hello hello.c -framework GLUT -framework OpenGL -framework Carbon
This compiles fine. However, when I try to run the executable, I get the following error:
GLUT Fatal API Usage: main loop entered with no windows created.
zsh: abort ./hello
According to this error message, the program was terminated because no windows were created. However, as I said, my simple.cpp program does not terminate (I have to forcefully terminate it), and it is written to create windows. So I'm guessing this means that windows are created in simple.cpp, but for some reason they just don't show up on MacOS? Can anyone else confirm this? Is the issue perhaps that blank windows don't show up on MacOS, and you need to include other graphical elements in order to make the window show?
EDIT2
The problem is that my understanding is that glutCreateWindow("simple"); in simple.cpp is supposed to create a window with "simple" as its title, so I don't understand why it isn't working.
EDIT3
Thanks to derhass's answer, I was able to make it work:
#define GL_SILENCE_DEPRECATION
#include <GLUT/glut.h>
void init() {
// code to be inserted here
}
void mydisplay() {
glClear(GL_COLOR_BUFFER_BIT);
// need to fill in this part
// and add in shaders
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutCreateWindow("simple");
init();
glutDisplayFunc(mydisplay);
glutMainLoop();
}
YOu did not include the call to glutInit() into your simple.cpp example. You can't call any other GLUT commands before this intialization, and doing so results in undefined behavior.

Unimplemented QColor error on compliation (C++)

I'm following Qt's Qt for Beginners tutorial and for some reason I am getting a compilation error when trying to build the simplest example of a gui. It looks like it's failing on button creation because it thinks that qcolor is unimplemented(?). I just downloaded the latest Qt 5.14.0 and installed it today, so it's possible that something happened during the install?
This is what my project layout looks like:
build-new_qt_project-Desktop_Qt_5_14_0_GCC_64bit-Debug:
Makefile
new_qt_project:
main.cpp
new_qt_project.pro
main.cpp:
#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QPushButton button ("Hello world !");
button.show();
return app.exec();
}
new_qt_project.pro:
TEMPLATE = app
TARGET = new_qt_project
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
And this is the output from trying to make it:
In file included from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qpixmap.h:45:0,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qicon.h:46,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtWidgets/qabstractbutton.h:44,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtWidgets/qpushbutton.h:44,
from ../../Qt5.14.0_2/5.14.0/gcc_64/include/QtWidgets/QPushButton:1,
from ../new_qt_project/main.cpp:2:
../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qcolor.h: In constructor ‘constexpr QColor::QColor(int, int, int, int)’:
../../Qt5.14.0_2/5.14.0/gcc_64/include/QtGui/qcolor.h:79:18: sorry, unimplemented: use of the value of the object being constructed in a constant expression
0) {}
^
make: *** [main.o] Error 1
I'm using the default (detected) kit to build it and it has the C++ compiler pointing to the one in /usr/bin, so I think that is correct. Is there something additional I've missed?
I think this is the problem:
Qt bug
update your gcc. up to 4.9 !!!
i had this problem and i used gcc 4.8 and after update it to gcc-7 it is now correct

Code::Blocks and Qt4

I´ve been trying desperately to get Qt4 running on my Code::Blocks. I´ve found the following page, with instructions I followed (German):
http://www.heikogorski.de/Compiler---Code/QT-und-Code--Blocks/qt-und-code--blocks.html
I downloaded Qt 4.8.2 like in the tutorial, checked every path 3 times and still, once I try to run the following very basic code:
#include <QApplication>
int main(int a, char ** b)
{
QApplication app(a,b);
return app.exec();
}
the window will just crash and I get the following error message in debugger:
Exception error at 0x6E1CC9A4 (QtCore4.dll) in qttest3.exe:
0xC0000005: Acesss violation at adress 0x01040806
Does anybody have an idea why?

GTKmm3 (GTK+ 3 C++) compiles but throws GLib-GIO-CRITICAL error when run

I've just started trying to get GTK+ 3 working with C++ and have tried to compile the simplest GTKmm Hello-World example.
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app =
Gtk::Application::create(argc, argv,
"org.gtkmm.examples.base");
Gtk::Window window;
window.set_default_size(200, 200);
return app->run(window);
}
After compiling with:
g++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`
There are no errors, however when I run the newly compiled application with:
./simple
I get the following error:
GLib-GIO-CRITICAL **: g_application_list_actions: assertion `application->priv->is_registered' failed
Segmentation fault (core dumped)
The code has been copied, unchanged from https://developer.gnome.org/gtkmm-tutorial/stable/sec-basics-simple-example.html.en so presumably it's likely to be a configuration issue, however I've frequently used this machine for PyGtk and CommandLine C++ without any issues.
Any help would be greatly appreciated.
This was a bug in gtkmm (probably triggered by a change in GTK+) that has been fixed in gtkmm:
https://git.gnome.org/browse/gtkmm/commit/?id=506cba376c0a0e09217ad7f5d597b6723d7f91a6
Maybe you can update your gtkmm version.

"Using OS scope before setting MAKEFILE_GENERATOR" in Qt

I have downloaded and installed Qt and I'm learning how to use it.
So, I created a new project myfristqt (empty project). I then added a main.cpp file with this code:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
First thing I noticed #include <QApplication> line is hightlighted with a red line as if QApplication was an unknown identifier. So, I compiled it to see what happens and here's the error I got:
(internal):1: error : Using OS scope before setting MAKEFILE_GENERATOR
Any idea why this is happening ? I'm using Windows XP
MAKEFILE_GENERATOR is a qmake variable.
This variable contains the name of the Makefile generator to use when generating a Makefile. The value of this variable is typically handled internally by qmake and rarely needs to be modified.
It define in QTDIR/mkspecs/PLATFORM/qmake.conf. Where PLATFORM is maybe cygwin-g++, win32-msvc200x on your Windows XP.