Results 1 to 12 of 12

Thread: why we have need of QApplication

  1. #1
    Join Date
    Mar 2006
    Posts
    20
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default why we have need of QApplication

    Hi,
    Im using QFont & QFontmatrics class only

    this my program

    QApplication a(argc,argv);

    QFont font( strFname, iFsize) ;
    font.setBold(true) ;
    font.setUnderline(true) ;
    font.setItalic(true) ;
    font.setStrikeOut(true) ;
    int iHeight , iWidth;
    QFontMetrics fm(font);
    QRect rct = fm.boundingRect(str);

    iHeight = rct.height();
    iWidth = rct.width();

    But I dont want to use QApplication a(argc,argv) class or variable..........

    Can i excute this programe without using QApplication a(argc,argv) & How?????

    Thanks & Regards
    Krishna

  2. #2
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: why we have need of QApplication

    Answer: If you are using a GUI app...u can't do without a Qapplication.

    I suggest you first read the docs. I presume you have Qt assistant on your system...run it and read what is said about QApplication...try doing all that without using this class

    If you are using a non gui class...then using Qt can be just considered to be a refinement of C++

  3. #3
    Join Date
    Mar 2006
    Posts
    20
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: why we have need of QApplication

    Thanks for reply.
    im using attached program, nothing else.
    I think there is no GUI application.But its showing error LIKE:::


    : undefined reference to `QFontMetrics::QFontMetrics[in-charge](QFont const&)'

    : undefined reference to `QFontMetrics::boundingRect(QString const&, int) const'

    : undefined reference to `QFontMetrics::~QFontMetrics [in-charge]()'

    Thanks & regards
    Krishna

  4. #4
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: why we have need of QApplication

    first paste your code between "["code"]"...."[/"code"]" blocks...(without the quotes)

    Since you haven't pasted your actual code, i presume you haven't included the files
    QApplication, QFont and QFontMetrics...

  5. #5
    Join Date
    Mar 2006
    Posts
    20
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: why we have need of QApplication

    This is my actual cod

    "
    #include <qapplication.h>
    #include <iostream.h>
    #include <string.h>
    #include <qfont.h>
    using namespace std;

    int GetPixOfChar(QString str , QString strFname, int iFsize)
    {
    QFont font( strFname, iFsize) ;
    font.setBold(true) ;
    font.setUnderline(true) ;
    font.setItalic(true) ;
    font.setStrikeOut(true) ;
    int iHeight , iWidth;
    QFontMetrics fm(font);
    QRect rct = fm.boundingRect(str);

    iHeight = rct.height();
    iWidth = rct.width();

    return iWidth;
    }
    int main( int argc, char **argv )
    {
    QApplication a(argc,argv);
    QString str= "i";
    QString Fname = "Times";
    int size = 14;
    int iWidth = GetPixOfChar(str , Fname , size);
    return 0;
    }

    "

    Please help me

    Thanks & Regards
    Krishna

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: why we have need of QApplication

    Did you actually link with Qt library?

  7. #7
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why we have need of QApplication

    Quote Originally Posted by Krishnacins
    Can i excute this programe without using QApplication a(argc,argv) & How?????

    Thanks & Regards
    Krishna
    Nope. You must use QApplication, QApplication does many things including initialising the window system. How are you going to use fonts without initialising the window system?

    What are your objections to using QApplication a(argc,argv) ?
    Save yourself some pain. Learn C++ before learning Qt.

  8. #8
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: why we have need of QApplication

    do the following:
    1. Read the docs
    2. I feel your constructors are not in the correct form:
    Qt Code:
    1. QFont ( const QString & family, int pointSize = -1, int weight = -1, bool italic = false )
    2. QFont ( const QFont & font, QPaintDevice * pd )
    3. QFont ( const QFont & font )
    To copy to clipboard, switch view to plain text mode 

    These are from my qt4 doc...i don't think this has changed since qt3...but you can confirm

    3. Read a Qt book...whenever you create a QApplication obj, you also need to call show and exec functions:

    Qt Code:
    1. //include files
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. // your code...
    8.  
    9. app.show() //actually shows the app window on screen!
    10.  
    11. return app.exec(); //you don't return 0, when using Qt!!
    12. }
    To copy to clipboard, switch view to plain text mode 

    4. you are creating font etc objs on the stack....thus you need to pass them by reference to the constructors above and not by value.

    5. You "seldom" need to use C++ in its true form with Qt...eg when you wish to use "cout" etc...try understanding qt and recoding ur prog...

    6. If there is no harm upgrade to qt4! please

    7. enclose your code in [ code] [ / code] blocks

    8. comment your code!!
    Last edited by nupul; 12th April 2006 at 05:51.

  9. #9
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why we have need of QApplication

    Quote Originally Posted by nupul
    do the following:
    2. I feel your constructors are not in the correct form:
    His constructors are fine as far as I can see.
    3. Read a Qt book...whenever you create a QApplication obj, you also need to call show and exec functions:
    You don't - not unless your program has a GUI or you specifically need an event loop.
    BTW, QApplication does not have a show() method.
    4. you are creating font etc objs on the stack....thus you need to pass them by reference to the constructors above and not by value.
    They are reference parameters. The way he is passing them is correct.
    5. You "seldom" need to use C++ in its true form with Qt...eg when you wish to use "cout" etc...try understanding qt and recoding ur prog...
    What on earth is C++'s "True Form"? An effective programmer will make use of the best of Qt as a library and use standard C++.
    8. comment your code!!
    Good advice, but the OP hardly needs comments for the little snippet that he posted.

    @Krishnacins It really looks like you need to #include <qfontmetrics.h>
    Last edited by Chicken Blood Machine; 12th April 2006 at 06:20.
    Save yourself some pain. Learn C++ before learning Qt.

  10. #10
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why we have need of QApplication

    sorry CBM...my mistake...think i answered too hastily....apologies for the mistake w.r.t show and exec...forgot to mention the need of a GUI/event-loop

  11. #11
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: why we have need of QApplication

    Quote Originally Posted by Chicken Blood Machine

    What on earth is C++'s "True Form"? An effective programmer will make use of the best of Qt as a library and use standard C++.)
    true form...hmmm...i dunno how to put it, lets say he doesn't use qt at all in it!
    but what you said is technically correct...i'll remember that!

    Good advice, but the OP hardly needs comments for the little snippet that he posted.
    It'd just help someone understand...why he's doing whatever he wishes to do...no matter how small the code!

  12. #12
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why we have need of QApplication

    Quote Originally Posted by nupul
    sorry CBM...my mistake...think i answered too hastily....apologies for the mistake w.r.t show and exec...forgot to mention the need of a GUI/event-loop
    No worries. I just wanted to make sure that the poster didn't get confused.
    Save yourself some pain. Learn C++ before learning Qt.

  13. The following user says thank you to Chicken Blood Machine for this useful post:

    nupul (13th April 2006)

Similar Threads

  1. Replies: 1
    Last Post: 8th January 2009, 13:36
  2. Must construct QApplication before QPaintDevice
    By sekatsim in forum Qt Programming
    Replies: 16
    Last Post: 8th June 2008, 00:00
  3. QApplication instance
    By nile.one in forum Qt Programming
    Replies: 9
    Last Post: 5th October 2007, 12:06
  4. Replies: 2
    Last Post: 16th March 2007, 09:04
  5. qapplication with open(/dev/name,O_RDWR) crashed???
    By ttbug in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 16th September 2006, 07:56

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
  •  
Qt is a trademark of The Qt Company.