PDA

View Full Version : Segmentation fault while creating Object for QApplication



nrabara
24th August 2009, 05:46
I have been using qt for embedded linux 4.5 on Embedded(arm) platform. While running simple qt application I got segmentation fault. I traced out and found that while creating object for QApplication its shows segmentation fault.(I have installed shared Lib at right location)
Below is my code..


int main(int argc, char * argv[])
{
printf("Inside main\n");
QApplication app(argc, argv); // Got error here
printf("object created \n");
Widget w;
w.show();
app.exec();

}

./my
Inside main
Segmentation fault


But I am able to create Object for QCoreApplication



int main(int argc, char * argv[])
{
printf("Inside main\n");
QCoreApplication app(argc, argv);
printf("object created \n");
a.arguments();
a.flush();

}

./my
Inside main
object created


I don't understand why its not creating object for QApplication??
What is going wrong??
I am not able to find the reason, can anybody help me out??

nish
24th August 2009, 06:29
are you linking the qtgui library in your project?

nrabara
24th August 2009, 07:02
no I am not linking qtgui library in my project. Is it required ??
I have cross compiled and placed the qt library in my file system. when i run its getting the shared Library information from that lib. I have copied core.so qui.so and network.so files.

You suggestion would be a great help for me.

nish
24th August 2009, 07:07
QApplication is in qtgui library.. so you need that...

nrabara
24th August 2009, 07:41
Mr Death, I am using arm-linux-gcc for cross compiling and its support rpath, so i dont need to set LD_LIBRARY_PATH ??
When i run qt application its able to get shared lib info....
but show segmentation fault while creating QApplication object....

if it dont get the shared lib info, it wont create QCoreApplication object also..

I am wrong? or missing something ??

your suggestion would be great help for me..

nix
24th August 2009, 08:06
Hi,

If you program crash when you try to use QApplication, it can be because you don't have the appropriate lib in your target.

Qt works with modules, GUI module and Core module are two of them.

QCoreApplication is part of the Core module (you need the libQtCore.so in your target).
QApplication is part of the GUI module ( you need the libQtGui.so in your target).
Of course you can check for dependency with ldd command.

QApplication is for app with GUI.
QCoreApplication if for app without GUI.

So, use the one that fit for your project.

nrabara
25th August 2009, 06:22
I have installed libQtGui.so , libQtCore.so and libQtNetwork.so files in my target board.

I have back traced with arm-linux-strace utility, its showing segmentation fault while trying to mmap() for fb0.;.
It not a problem with directory path... I have traced out that qt application is able to find libQtGui.so , libQtCore.so and libQtNetwork.so.

my
libQtGui.so = 11 MB
libQtCore.so = 3.2 MB and
libQtNetwork.so = 1.1 MB

I have 32 MB of FLASH and 32MB SDRAM. whether it's problem with memory??

wysota
25th August 2009, 09:05
Does your ARM device have an X11 server?

nrabara
25th August 2009, 10:47
No on my ARM i don't have X11.
I have connected TFT 640*480 and run qt framebuffer test program, Its shows me 3 rectangles on TFT so framebuffer fb0 is working correctly.
Is X11 is required??

wysota
25th August 2009, 11:13
It's not required but you probably have to somehow tell QApplication not to try to connect to X server :) With Qtopia you would use QtopiaApplication but with bare Qt/Embedded you probably need to use QApplication. You did compile Qt/Embedded for your device, right? You didn't just cross-compile the desktop edition for ARM?

nrabara
25th August 2009, 12:21
I do remember that i have used qt-embedded-linux-open-source-4.5.
I am getting following message when i try to run qt application.

# ./JS
QWSSocket::connectToLocalFile could not connect :: Connection refused
No Qt for embedded linux server appears to be running
If you want to run the program as a server
add -qws

when I run with # ./JS -qws
Segmentation fault

any suggestion would be appreciable....

wysota
25th August 2009, 12:48
Did you read Qt Embedded Display Management?

nrabara
26th August 2009, 12:02
Yes I have read it,

I have used following..
export QT_DIR=/home/qt
export LD_LIBRARY_PATH=$QT_DIR/lib
export QWD_DISPLAY=LinuxFb

I have intalled libQtGui.so.4 , libQtCore.so.4 ,libQtNetwork.so.4 in my board at /home/qt/lib.(same path user while cross compiling with arm-linux-gcc)
I have also intalled fonts to /home/qt/fonts
i have place qmake in /usr/bin or my board

I dont under understand why it's(segmentation fault) happening with QApplication only why not with QCoreApplicaton.

Your suggestion would be a great help for me.

wysota
26th August 2009, 12:21
Does the user have access rights to write to the framebuffer?

QCoreApplication works because the application doesn't try to access the framebuffer.

nrabara
26th August 2009, 12:27
Yes user have rights to access /dev/fb0
Even I can run qt example code of frambuffer(examples/qws/framebuffer.) on board, and Its show me three rectangles on my display.

wysota
26th August 2009, 12:55
Do other examples work as well?

nrabara
26th August 2009, 13:17
All the example having QApplication object show segmentation fault.

But for QCoreApplication object, i can use QDateTime, QDate etc.. sub classes of QCoreApplication. It's works fine with QCoreApplication.

Is there any other way to test QApplication object, I mean
Can ./configure affect Qt Gui ?? I have tried with full configuration also.

Your suggestion would be great help for me..

wysota
26th August 2009, 13:23
Your problem is deployment, not compilation. Could you post a backtrace of an exemplory crash? An strace showing files being opened (and statuses of the calls) would be nice as well.

nrabara
26th August 2009, 15:27
Below is my test application code

main.cpp file



#include <QtGui/QApplication>
#include <QLabel>
#include "widget.h"

int main(int argc, char *argv[])
{
printf("Inside main\n");
unsigned int loop;
QApplication a(argc, argv);
printf("argc = %d \n",argc);
for(loop=0;loop<argc;loop++)
{
printf("argv[%d] = %s \n",argc,argv[loop]);
}
Widget w;
w.setFixedSize(200,200);
w.show();
return a.exec();
}

widget.cpp file

#include "widget.h"

Widget::Widget(QWidget *parent)
: QWidget(parent)
{
}

Widget::~Widget()
{

}

widget.h file

#ifndef WIDGET_H
#define WIDGET_H

#include <QtGui/QWidget>

class Widget : public QWidget
{
Q_OBJECT

public:
Widget(QWidget *parent = 0);
~Widget();
};

#endif // WIDGET_H



Back trace of the above code is attached - file : QApplication_backtrace.txt

I have also attached back trace of qt's example code - framebuffer , file : QtFramebuffer_exampleCode.txt

Your suggestion would be a great help for me..

wysota
26th August 2009, 15:40
This is an strace. What about a debugger backtrace?

The strace suggests there is a problem with mapping the framebuffer to memory.

nix
26th August 2009, 16:29
Can you post result for the following command "fbset --info" too, thx.

Vis
28th September 2010, 10:59
Hi,

I am trying something similar on a an embedded system, albeit a different one.

How was this resolved, if at all?

I know that this thread is dated, but anything that can be recalled will be helpful.

Cheers,
--
Vis