PDA

View Full Version : unable to run Console application



jay
12th June 2008, 05:54
Dear all,
I am running the below sample in console mode. without startX.
The program crashes in the below line.
"QFont font;"

#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv, QApplication::Try);
QFont font;
QFontMetrics metrics(font);
int width = metrics.width("test");
return app.exec();
}

Please anyone help me to solve this.
I am using Qt4.4.0 in Slackware.

Note: I have builed Qt with flags (-no-sm -no-X11 etc.),

Thank you.

JimDaniel
12th June 2008, 06:05
You need to initialize your font object with a font before you can find out about its metrics. Try this:

QFont font("Arial");

ChristianEhrlicher
12th June 2008, 07:48
QFont is part of QtGui and most of the QtGui classes need (*surprise*) X11 to work.

jay
12th June 2008, 08:28
first, many thanks for both answers.
JimDaniel,
If we didn't specify any font, it takes the default font. so that I have used.(It's my fault - I didn't give my exact requirement).
Since In my system, I didn't installed X-Server. so it doesn't recognizes fonts.
I think this may be the problem(I don't know how to solve this).

ChristianEhrlicher,
my requrement is I don't want to start X, its enough to run in console.
so that I have put 'QApplication::Try' as a third argument.

my exact question is: without startX, is it able to use fonts (with some fonts are installed)?

Regards,
Jay.

ChristianEhrlicher
12th June 2008, 08:33
I already answered the question. If you don't trust me, simply take a look into the sources and you'll see that x11 functions are needed to create a qfont.