Results 1 to 5 of 5

Thread: unable to run Console application

  1. #1
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question unable to run Console application

    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.

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: unable to run Console application

    You need to initialize your font object with a font before you can find out about its metrics. Try this:

    QFont font("Arial");

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to run Console application

    QFont is part of QtGui and most of the QtGui classes need (*surprise*) X11 to work.

  4. #4
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to run Console application

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to run Console application

    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.

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 09:45
  2. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  3. run a console application through a gui interface
    By gurinder in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2008, 12:52
  4. Console application suspense
    By TheGrimace in forum Newbie
    Replies: 6
    Last Post: 1st October 2007, 14:52
  5. build a gui ontop of a console application
    By aegis in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2007, 12:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.