PDA

View Full Version : Including 3rd party software makes my program crash with QFileDialog



ruben.rodrigues
12th January 2011, 20:12
Hi all!

I am including a 3rd party software called Halcon that handles and treats camera pictures. As I have seen in the example I should include the following lines in the .pro file:

LIBS += -L\"$/opt/halcon/lib/x64-linux2.4-gcc40\"
unix:LIBS += -lhalconcpp -lhalcon -ldl -lpthread

The problem is that as soon as I add the -lhalconcpp and/or the -lhalcon I can use the QFileDialog to search for files... :( it basically crashes everything.

any idea why?

thanks!

SixDegrees
12th January 2011, 20:25
What crashes? The build? The link? The running application? What error messages are produced?

ruben.rodrigues
12th January 2011, 20:33
Run time error, message "segmentation fault", command: QString fileName = QFileDialog::getOpenFileName(this, tr("OpenFile: "),"/home/rrodrigues/Desktop");
The whole application crashes when I call the command above.

SixDegrees
12th January 2011, 21:05
There's nothing obviously wrong with the call. Try a different directory name, or leave it off entirely (that should start the dialog in the directory where the application was started from) and see if that works. If so, the problem is with the particular directory you're trying to access; existence or permissions would be the obvious things to check.

Failing that, turn a debugger loose on it and see if you can pin down the source of the error.

Also, try doing a 'make clean' and a new 'make' before proceeding, just in case.

ruben.rodrigues
12th January 2011, 21:12
just as addicional information I created a new project (with only a button that opens the FileDialog) and if I add the "LIBS" to my pro file it doesn't work, if I take it it works again.
I also tried some variations like take some parameters and try to change others but still no success.

ruben.rodrigues
24th January 2011, 10:08
Hi all!

Because I have to include a library from a company called Halcon I can't use the QFileDialog. I already tried to include the library in many different ways and it always causes conflict when I try to browser my folders with the QFileDialog. It always terminates.

Is there any other way to implement a File Dialog that is stable and easy to include?

Thank you in advance.

high_flyer
24th January 2011, 10:27
This sounds highly improbable.
The problem is probably in the way you are using QFileDialog, and not in the fact you are linking to Qt.
If you show the code, and explain what you did, and the error you get, we probably might help you to make this work.
but you have to supply us with sufficient data to help you.

ruben.rodrigues
24th January 2011, 11:53
I already posted the problem in another thread (http://www.qtcentre.org/threads/37767-Including-3rd-party-software-makes-my-program-crash-with-QFileDialog?highlight=) but I didn't get answers.
I know it sound crazy impossible but if I had the -halcon include it doesn't work (terminates with segmentation fault) and if I take the include it works just fine.

It is no problem with my code to open a file dialog but because I have to use the halcon library I would like to know about other way to open a file browser, please.

thank you.

wysota
24th January 2011, 13:19
Please provide a minimal compilable example reproducing the problem.

ruben.rodrigues
24th January 2011, 14:37
Please provide a minimal compilable example reproducing the problem.

I am not trying to solve the problem because I already lost too much time trying to solve this and I couldn't find the solution. I have other thread where I tried to solve this situation here (http://www.qtcentre.org/threads/37767-Including-3rd-party-software-makes-my-program-crash-with-QFileDialog?highlight=).
Off course I would appreciate if someone reproduced the problem in their computer but that's probably asking too much. You would have to download Halcon 8.0 and include it as I did in any qt project and you see that you can't use the QFileDialog anymore.

Do you know other way of opening a file dialog or do I have to find a magical way of solve this problem.

thank you.

wysota
24th January 2011, 14:46
Do you know other way of opening a file dialog or do I have to find a magical way of solve this problem.
Patience is a virtue. Provide a minimal compilable example, run it and post the backtrace of the crash. Then we can talk about it. I don't know what this Halcon lib does but until we know why your code crashes, there is no point in blaming anyone.

By the way, threads merged.

ruben.rodrigues
24th January 2011, 14:53
Patience is a virtue. Provide a minimal compilable example, run it and post the backtrace of the crash. Then we can talk about it. I don't know what this Halcon lib does but until we know why your code crashes, there is no point in blaming anyone.

By the way, threads merged.

Can you just tell me, please, if there is another known way to open a file dialog?

wysota
24th January 2011, 15:44
Can you just tell me, please, if there is another known way to open a file dialog?

You can always use the native API. Of course this is the same what Qt does when you use the static call (which you probably do) so it's likely you'll end up with the same result but since you really want to waste time, I'm not going to stop you. When you decide to come back for more help, please be sure to bring a backtrace of the crash with you.

ruben.rodrigues
24th January 2011, 16:39
You can always use the native API. Of course this is the same what Qt does when you use the static call (which you probably do) so it's likely you'll end up with the same result but since you really want to waste time, I'm not going to stop you. When you decide to come back for more help, please be sure to bring a backtrace of the crash with you.

is the backtrace the DSF disassembly on Eclipse for ubuntu?

wysota
24th January 2011, 16:50
is the backtrace the DSF disassembly on Eclipse for ubuntu?

https://wiki.ubuntu.com/Backtrace
http://en.wikipedia.org/wiki/Stack_trace

ruben.rodrigues
24th January 2011, 17:07
I ran a debug and the only thing I got after the crash was this line:
mi_cmd_var_create: Usage: NAME FRAME EXPRESSION.

I also took a screenshot where the command that makes the crash is highlighted.

thank you!

Added after 4 minutes:

backtrace with gdb as attachment because of characters limit.

I still can't see much from the backtrace.
Any help appreciated.
Thank you! (also for telling me how to do the backtrace).

Backtrace made with gdb as attachment.
any help appreciated.
thank you. (also for telling me how to do it.)

wysota
24th January 2011, 17:17
Please also provide output of "ldd libhalon.so" (or equivalent). You may have a conflict in one of gtk libraries. Qt has nothing to do with your situation.

ruben.rodrigues
24th January 2011, 18:26
rrodrigues@espLPT08:/opt/halcon/lib/x64-linux2.4-gcc40$ ldd libhalcon.so
linux-vdso.so.1 => (0x00007fffd3b61000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f6c72254000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f6c71f4d000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f6c71d30000)
librt.so.1 => /lib/librt.so.1 (0x00007f6c71b28000)
libm.so.6 => /lib/libm.so.6 (0x00007f6c718a3000)
libc.so.6 => /lib/libc.so.6 (0x00007f6c71530000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f6c7132c000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f6c71129000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f6c70f0c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6c73b45000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f6c70d07000)

and

rrodrigues@espLPT08:/opt/halcon/lib/x64-linux2.4-gcc40$ ldd libhalconcpp.so
linux-vdso.so.1 => (0x00007fff2f9ff000)
libhalcon.so => /opt/halcon/lib/x64-linux2.4-gcc40/libhalcon.so (0x00007f8660095000)
libm.so.6 => /lib/libm.so.6 (0x00007f865fde9000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f865fad8000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f865f8c1000)
libc.so.6 => /lib/libc.so.6 (0x00007f865f54f000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f865f34a000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f865f138000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f865ee31000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f865ec14000)
librt.so.1 => /lib/librt.so.1 (0x00007f865ea0c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8661ce7000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f865e809000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f865e5ec000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f865e3e7000)

I guess the problem is with the linux-vdso...how do I solve it?

also sorry about the 1hour delay but I had to drive home.

wysota
24th January 2011, 18:35
No, I don't think that's the problem, see here: http://blogs.igalia.com/aperez/2009/01/the-story-of-linux-gatevdsoso/

Is your Qt compiled for 64 bits (use ldd on one of its libs)?

By the way, please provide data (backtrace, ldd) for your minimal example and not your full-blown multithreaded project. I think your backtrace was from tha latter.

ruben.rodrigues
24th January 2011, 18:59
the lib I use is this:
rrodrigues@espLPT08:/esp/IbexClientPlugin/plugins$ ldd libldiclient.so
linux-vdso.so.1 => (0x00007fffa7490000)
libhalconcpp.so => /opt/halcon/lib/x64-linux2.4-gcc40/libhalconcpp.so (0x00007fc51fab9000)
libhalcon.so => /opt/halcon/lib/x64-linux2.4-gcc40/libhalcon.so (0x00007fc51e404000)
libdl.so.2 => /lib/libdl.so.2 (0x00007fc51e1d8000)
libQtSql.so.4 => /usr/lib/libQtSql.so.4 (0x00007fc51df9a000)
libQtGui.so.4 => /usr/lib/libQtGui.so.4 (0x00007fc51d3e6000)
libQtCore.so.4 => /usr/lib/libQtCore.so.4 (0x00007fc51cfae000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fc51cd92000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fc51ca82000)
libm.so.6 => /lib/libm.so.6 (0x00007fc51c7fc000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fc51c5e5000)
libc.so.6 => /lib/libc.so.6 (0x00007fc51c273000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007fc51c060000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007fc51bd59000)
librt.so.1 => /lib/librt.so.1 (0x00007fc51bb51000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc5202d9000)
libaudio.so.2 => /usr/lib/libaudio.so.2 (0x00007fc51b937000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00007fc51b710000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007fc51b48a000)
libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007fc51b243000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x00007fc51b03a000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x00007fc51ae1f000)
libz.so.1 => /lib/libz.so.1 (0x00007fc51ac06000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007fc51a941000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007fc51a737000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007fc51a504000)
libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x00007fc51a2ff000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007fc51a0fb000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007fc519edf000)
libXt.so.6 => /usr/lib/libXt.so.6 (0x00007fc519c79000)
libpcre.so.3 => /lib/libpcre.so.3 (0x00007fc519a48000)
libuuid.so.1 => /lib/libuuid.so.1 (0x00007fc519843000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007fc519619000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007fc519413000)

I also tried as an application with no plugins:

rrodrigues@espLPT08:~/workspace/LDI_HMI$ ldd LDI_HMI
linux-vdso.so.1 => (0x00007fff4cd1c000)
libhalconcpp.so => /opt/halcon/lib/x64-linux2.4-gcc40/libhalconcpp.so (0x00007f33824c4000)
libhalcon.so => /opt/halcon/lib/x64-linux2.4-gcc40/libhalcon.so (0x00007f3380e0f000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f3380c0b000)
libQtSql.so.4 => /usr/lib/libQtSql.so.4 (0x00007f33809cd000)
libQtGui.so.4 => /usr/lib/libQtGui.so.4 (0x00007f337fe19000)
libQtCore.so.4 => /usr/lib/libQtCore.so.4 (0x00007f337f9e2000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f337f7c6000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f337f4b6000)
libm.so.6 => /lib/libm.so.6 (0x00007f337f231000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f337f01a000)
libc.so.6 => /lib/libc.so.6 (0x00007f337eca8000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f337e9a1000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f337e78f000)
librt.so.1 => /lib/librt.so.1 (0x00007f337e587000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3382a5e000)
libaudio.so.2 => /usr/lib/libaudio.so.2 (0x00007f337e36e000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00007f337e147000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f337dec1000)
libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007f337dc7b000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x00007f337da72000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x00007f337d857000)
libz.so.1 => /lib/libz.so.1 (0x00007f337d63f000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f337d37a000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007f337d170000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007f337cf3e000)
libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x00007f337cd39000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f337cb1d000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f337c91a000)
libXt.so.6 => /usr/lib/libXt.so.6 (0x00007f337c6b4000)
libpcre.so.3 => /lib/libpcre.so.3 (0x00007f337c484000)
libuuid.so.1 => /lib/libuuid.so.1 (0x00007f337c27f000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007f337c055000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f337be50000)

wysota
24th January 2011, 22:11
Could we focus on the minimal example please?
Compile this one and see if it crashes on you. If it does, provide a backtrace and ldd of the program and libQtCore.so

#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QFileDialog::getOpenFileName();
return 0;
}

and this project file:
TEMPLATE=app
SOURCES += main.cpp
LIBS += -L/opt/halcon/lib/x64-linux2.4-gcc40 -lhalcon -lhalconcpp

And please post the result of "gcc -v" and "uname -rm" on your system.

ruben.rodrigues
25th January 2011, 06:27
Could we focus on the minimal example please?
Compile this one and see if it crashes on you. If it does, provide a backtrace and ldd of the program and libQtCore.so

#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QFileDialog::getOpenFileName();
return 0;
}

and this project file:
TEMPLATE=app
SOURCES += main.cpp
LIBS += -L/opt/halcon/lib/x64-linux2.4-gcc40 -lhalcon -lhalconcpp

And please post the result of "gcc -v" and "uname -rm" on your system.

main.cpp:



#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QFileDialog::getOpenFileName();
return 0;
}


pro file:


TEMPLATE = app
TARGET = filedialog_test
QT += core
SOURCES += main.cpp
LIBS += -L/opt/halcon/lib/x64-linux2.4-gcc40 -lhalcon -lhalconcpp


gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
2.6.28-19-generic x86_64

backtrace as attachment.

thank you!

wysota
25th January 2011, 09:19
I don't think we will solve this here. The crash is deep inside Gnome's libraries. If you ran your app in KDE, it would probably work. I can only suggest a workaround - pass DontUseNativeDialog option to QFileDialog. You will then get Qt's own file dialog instead of the one native to your desktop and with a bit of luck it will not crash. Unless it is libpng which causes the crash. You either have a misconfiguration in your system or these halon libs are really messed up. With a bit of bad luck it is probable that every call to libpng will end up with a crash.

ruben.rodrigues
25th January 2011, 10:06
I don't think we will solve this here. The crash is deep inside Gnome's libraries. If you ran your app in KDE, it would probably work. I can only suggest a workaround - pass DontUseNativeDialog option to QFileDialog. You will then get Qt's own file dialog instead of the one native to your desktop and with a bit of luck it will not crash. Unless it is libpng which causes the crash. You either have a misconfiguration in your system or these halon libs are really messed up. With a bit of bad luck it is probable that every call to libpng will end up with a crash.

Hey! It works if I use the option DontUseNativeDialog. I am still figuring out how to get the value of the search because I just tested like this:

QFileDialog dlg(this);
dlg.setOption(QFileDialog::DontUseNativeDialog, false);
dlg.exec();

If I do this:

QString fileName = QFileDialog::getOpenFileName(this, tr("OpenFile: "),"/home/rrodrigues/Desktop",QFileDialog::DontUseNativeDialog);

or

QString fileName = QFileDialog::getOpenFileName(this, tr("OpenFile: "),QString("/home/rrodrigues/Desktop"),QFileDialog::DontUseNativeDialog);

it tell me no matching function:

no matching function for call to ‘QFileDialog::getOpenFileName(ldiclient* const, QString, const char [25], QFileDialog::Option)’
no matching function for call to ‘QFileDialog::getOpenFileName(ldiclient* const, QString, QString, QFileDialog::Option)’

I am already very happy that I can see the dialog but can you tell me what is wrong with the function?

wysota
25th January 2011, 10:16
Look at the available variants of getOpenFileName(), the Options argument is the last one so you have to explicitly pass all the previous ones.

ruben.rodrigues
25th January 2011, 12:42
I tried like this but it doesn't work: (it terminates like it used before)

QFileDialog dlg(this);
dlg.setOption(QFileDialog::DontUseNativeDialog, false);
QString test = dlg.getOpenFileName();
dlg.exec();
cout << test.toStdString() << endl;

If I do it like this it works but I can't get the file name:

QFileDialog dlg(this);
dlg.setOption(QFileDialog::DontUseNativeDialog, false);
dlg.exec();

wysota
25th January 2011, 13:15
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Images (*.png *.xpm *.jpg)"), 0, QFileDialog::DontUseNativeDialog);

or

QFileDialog dlg(this); // you don't need to set DontUseNativeDialog here
QStringList selectedFiles;
if(dlg.exec()){
selectedFiles = dlg.selectedFiles();
}

ruben.rodrigues
25th January 2011, 16:22
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Images (*.png *.xpm *.jpg)"), 0, QFileDialog::DontUseNativeDialog);

or

QFileDialog dlg(this); // you don't need to set DontUseNativeDialog here
QStringList selectedFiles;
if(dlg.exec()){
selectedFiles = dlg.selectedFiles();
}

Thanks a lot man! it works like a charm now. it was kind of a weird error but good thing that qt has this DontUseNativeDialog thing.

Also sorry for the delay but I was busy with other parts of the project.