QApplication object from a shared library
-
Hi,
Operating system : Ubuntu 12.04
I got crash while trying to create QApplication object. Code I have used is given below.
int argc = 1;
char * argv[] = {"QT_APP", NULL};
QApplication *pqApp;pqApp = new QApplication(argc, argv); // Got crash here
When I tried to debug got backtrace as given below:
(gdb) bt
#0 0xa4ec95bb in ?? () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#1 0xa4ed4c3b in QString::arg(long long, int, int, QChar) const () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#2 0xa503adca in QCoreApplication::applicationFilePath() () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#3 0xa503cd67 in QCoreApplication::applicationDirPath() () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#4 0xa4e3d96d in ?? () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#5 0xa4e3dd39 in QLibraryInfo::platformPluginArguments(QString const&) () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#6 0xa53caaab in QGuiApplicationPrivate::createPlatformIntegration() () from /home/user/Qt/5.5/gcc/lib/libQt5Gui.so.5
#7 0xa8a9265c in ?? ()
#8 0xabfc9460 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)I am trying to open QT GUI from a '.so' which is loaded by JAVA application.
-
Hi,
Operating system : Ubuntu 12.04
I got crash while trying to create QApplication object. Code I have used is given below.
int argc = 1;
char * argv[] = {"QT_APP", NULL};
QApplication *pqApp;pqApp = new QApplication(argc, argv); // Got crash here
When I tried to debug got backtrace as given below:
(gdb) bt
#0 0xa4ec95bb in ?? () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#1 0xa4ed4c3b in QString::arg(long long, int, int, QChar) const () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#2 0xa503adca in QCoreApplication::applicationFilePath() () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#3 0xa503cd67 in QCoreApplication::applicationDirPath() () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#4 0xa4e3d96d in ?? () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#5 0xa4e3dd39 in QLibraryInfo::platformPluginArguments(QString const&) () from /home/user/Qt/5.5/gcc/lib/libQt5Core.so.5
#6 0xa53caaab in QGuiApplicationPrivate::createPlatformIntegration() () from /home/user/Qt/5.5/gcc/lib/libQt5Gui.so.5
#7 0xa8a9265c in ?? ()
#8 0xabfc9460 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)I am trying to open QT GUI from a '.so' which is loaded by JAVA application.
@Jeenus
What do you mean by "open QT GUI from a '.so' which is loaded by JAVA application"? If you are already inside some application, you cannot create a brand new Qt application inside it, just one application at a time with its ownargc/argvfrom command-line. -
@Jeenus
What do you mean by "open QT GUI from a '.so' which is loaded by JAVA application"? If you are already inside some application, you cannot create a brand new Qt application inside it, just one application at a time with its ownargc/argvfrom command-line.@JonB In my scenario, we are using a third party JAVA application. This application loads a shared library. From this application, we are trying to open a QT GUI. This approach is working in Windows. But in Linux getting crash.
JAVA application (Third party application) -> Shared library -> Open QT GUI
-
@JonB In my scenario, we are using a third party JAVA application. This application loads a shared library. From this application, we are trying to open a QT GUI. This approach is working in Windows. But in Linux getting crash.
JAVA application (Third party application) -> Shared library -> Open QT GUI
@Jeenus
Hi
Be aware that on windows platform ( at least)
the first argument is the full path to exe normally.
You give it QT_APP which it might not like.
Not tested what happens if replaced but at least take that into account when
debugging it. It might need it for locating plugins etc. -
@Jeenus
Hi
Be aware that on windows platform ( at least)
the first argument is the full path to exe normally.
You give it QT_APP which it might not like.
Not tested what happens if replaced but at least take that into account when
debugging it. It might need it for locating plugins etc.the first argument is the full path to exe normally.
You give it QT_APP which it might not like.Interesting.
argv[0]to a C program can contain any string in any format, even if it usually might be indicating where the program is being run; it certainly should not cause code parsing it to fall over. Yet it does look likeQLibraryInfo::platformPluginArgumentsmight be trying to use it to calculate a path in a naughty way from the traceback. -
the first argument is the full path to exe normally.
You give it QT_APP which it might not like.Interesting.
argv[0]to a C program can contain any string in any format, even if it usually might be indicating where the program is being run; it certainly should not cause code parsing it to fall over. Yet it does look likeQLibraryInfo::platformPluginArgumentsmight be trying to use it to calculate a path in a naughty way from the traceback. -
@JonB
Well , maybe its a windows thing ?
or only when run from creator ?This is plain c template.

and run standalone

@mrjj
When C was written, under UNIX the system call to launch an executable was one of :int execl(const char *path, const char *arg, ... /* (char *) NULL */); int execv(const char *path, char *const argv[]);The
pathgave the actual executable to run, but was not available to the executed program. It received only theargs orargv. It is customary for the calling program to pass the firstargorargv[0]as the name or path of the program being executed bypath, but not compulsory; if you want to goexeclp("/bin/ls", "$rubbish&", "-l", NULL)you can, and it will still do/bin/ls -l, the firstargnotwithstanding.These arrive at C's
main(int argc, char *argv[]). With a minimum of1forargc, andargv[0]being non-NULL. Arguments to the program are from the secondargorargv[1]onward. What you do, if anything, withargv[0], in your C program is up to you. But if you rely on it relating to the program being run, it may not.Now, that's C's
argc&argv. What Windows/your C runtime may do in the way of setting upargv[0]from::CreateProcess()or similar is another matter. -
Ok. so it was a windows thing :)
I wonder if Qt expects the path or if its something completely different for poster.
ps. Good insight. -
The only QString::arg() call I see is
QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid()));
Why this should crash - no idea. Install debug informations for Qt and post the backtrace so we see the line numbers.
-
You said you are on Ubuntu 12.04. If you are using the default GCC and G++ , it is too old in ubuntu 12.04. You probably need to upgrade gnu compile collection
PS: better to upgrade ubuntu to 18.04 ( or 16.04 at least )