Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Using wrapped Qt segfaults on Linux with only a basic example
Jebbs last edited by
I posted this exact thing on Stack Overflow, but then I thought I would have better luck here.
I've been experimenting with wrapping some Qt classes with a C interface to use with my latest D project. For what ever reason, this code works fine on Windows but segfaults on Linux and I haven't been able to track down the reason behind it. I haven't tried building on OSX yet.
I'm using Qt 5.3, and running Linux Mint.
The code is kind of spread out over a few different files so I thought it might be easier if I put all the related code into some pastebins.
"QApplication wrapper stuff":http://pastebin.com/2bzm27e8
"QMainQWindow wrapper stuff":http://pastebin.com/hsiM6Rxy
These are very thin wrappers though, so even if you don't look at them it should be easy enough to understand my test program.
int main( int argc, char* argv)
Qt_Application* app = Qt_Application_create(argc, argv); Qt_MainWindow* window = Qt_MainWindow_create(); Qt_MainWindow_show(window);//<- Segfault happens here Qt_Application_exec(app); Qt_Application_destroy(app); Qt_MainWindow_destroy(window); return 0;
Due to some printf tests, I know the segfault happens on when I try to call Qt_MainWindow_show, and likewise I know the window object exists when I pass it so that isn't the cause. Also, if I comment Qt_MainWindow_show out, Qt_Application_exec will get called no problem so as far as I know the wrapped objects are being created correctly.
When I run gdb, it says:
bq. Program received signal SIGSEGV, Segmentation fault.
0x00007ffff789a92a in strlen () from /lib/x86_64-linux-gnu/libc.so.6
getting the backtrace at the point of the segfault shows this:
bq. #0 0x00007ffff789a92a in strlen () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff6b6c6bc in QCoreApplication::arguments() ()
#2 0x00007ffff1470213 in ?? ()
#3 0x00007ffff14705f9 in ?? ()
#4 0x00007ffff147d127 in ?? ()
#5 0x00007ffff1470009 in ?? ()
#6 0x00007ffff5d47e03 in QWindow::create() ()
#7 0x00007ffff716b97a in QWidgetPrivate::create_sys(unsigned long long, bool, bool) () from /home/jebbs/Qt/5.3/gcc_64/lib/libQt5Widgets.so.5
#8 0x00007ffff714e6f5 in QWidget::create(unsigned long long, bool, bool) ()
#9 0x00007ffff71512ea in QWidget::setVisible(bool) ()
#10 0x00007ffff7bd8205 in Qt_MainWindow_show ()
#11 0x0000000000400922 in main (argc=1, argv=0x7fffffffe158) at main.cpp:22 <-actually points to Qt_MainWindow_show(window), but this is from a test with printf's in it
So it looks like some string somewhere is NULL and strlen cries? I couldn't find any reason that QMainWindow.show() might segfault. Any pointers into where I should look or what I should do next would be an excellent help.