A simple class derived from QApplication Seg-faults
-
Hey, The code paste worked ! I noticed the '@@' did not wrap the code text the first few times ????? My fat fingers ;-)
-
Just wondering... Are you building your application by hand ?
-
By hand? I recall when "by hand" refered to using dip switches ;-)
I think you mean I use moc and g++ in my Makefile, which is correct. The "commandline" referenced in first of this post is an equivelent to the Makefile execution.
-
Did you wrote the Makefile yourself ?
-
Yes, by hand ;-)
-
Ok... Then let's try it the Qt way...
Move your Makefile and _moc.h somewhere safe and run:@
qmake -project
qmake
make
@And start your application again
-
SGaist,
I did get the "Simple derived QApplication" to build and execute with qmake.
We require that the code builds in our current make environment.
What I have discovered is adding the compiler flag "-fomit-frame-pointer" will eliminate the seg-fault. Can you explain how not using this flag will cause a seg-fault ? The following is complete source and build commands:@/usr/lib64/qt4/bin/moc QtC4Test.h -I/usr/include/QtGui -o QtC4Test_moc.cx
g++ -Wall -fomit-frame-pointer -I/usr/include/QtGui QtC4Test.cpp -o QtC4Test -lQtGui -lQtCore -lpthread
@The Source .h:
@#ifndef QTC4TEST_H_
#define QTC4TEST_H_#include <QtGui/QApplication>
#include <QtGui/QLabel>class C4Window : public QApplication
{
Q_OBJECTpublic:
C4Window( int argc, char **argv );
};#endif /* QTC4TEST_H_ */
@The Source .cpp:
@#include "QtC4Test.h"
#include "QtC4Test_moc.cx"C4Window::C4Window( int argc, char **argv ):QApplication( argc, argv )
{
};int main( int argc, char **argv )
{
C4Window c4w( argc, argv );
QLabel qtl( "Hello world!" );
qtl.setVisible(true);
return(c4w.exec());
}
@ -
Then you should analyze the Makefiles generated using qmake. You'll see that there's a lot of setup done for your (i.e. the various flags to match what was used to build Qt) Also, take a look at the mkspec used for your platform.
Since you are testing Qt you should rather go with the documentation examples and demos. Subclassing QApplication is rarely needed and certainly not in your test application. I wonder where you got this code.
-
I am sorry SGaist,
I am confused by your reply.
I am posting here to get some answers to my questions.
I had assumed all of your questions were answered previously in the post.http://qt-project.org/forums/viewreply/141143/
http://qt-project.org/forums/viewreply/141315/Yes, I did analyse the files generated by the qmake process you have suggested.
That is exactly where I got the flag “-fomit-frame-pointer”, it is a difference I found in the qmake build and my build.
Note that the -O2 flags is what I currently use for Qt's g++ compile.
I have systematicly eliminated the other flags in -O2 to determine that “-fomit-frame-pointer”
will provide a successful (non-seg-faulting) build of the example code.I beg to question if it is that important to know where the code came from.
What is provided is complete, so no need to access other resources.
Is there an error in this code?
I have previously questioned if there is a problem deriving from QApplication.
That question was left unanswered so I assumed sub classing QApplication is not a problem.Yes I have been searching for an example of my intended usage of Qt but have not found anything exceptable.
I have explained in this post how I wish to use Qt, and again with no response I assumed there is not a problem with my intentions.
I would appreciate any suggestions for examples that provide a similar implementation of Qt:
"My planed implementation of Qt is “simply” add some widgets to an existing X11 application."
http://qt-project.org/forums/viewreply/141143/Thanks
-
No, it's not important, I am just curious to know.
There is nothing wrong deriving from QApplication, but in the case of this example, it's pretty useless and would only add code to maintain that is not needed from the start.
I don't know the X11 platform enough to give you a definitive answer. I know that Qt provides some classes to embedded a X11 window (using the XEmbed specification) in an application so I suppose the opposite should also be doable.
-
C4Window construction function not correct, it should be C4Window(int &argc, char **argv), see QApplication construction
-
This post is deleted!