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...
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...
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
Did you actually link with Qt library?![]()
do the following:
1. Read the docs
2. I feel your constructors are not in the correct form:
Qt Code:
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:
//include files int main(int argc, char *argv[]) { // your code... app.show() //actually shows the app window on screen! return app.exec(); //you don't return 0, when using Qt!! }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.
His constructors are fine as far as I can see.Originally Posted by nupul
You don't - not unless your program has a GUI or you specifically need an event loop.3. Read a Qt book...whenever you create a QApplication obj, you also need to call show and exec functions:
BTW, QApplication does not have a show() method.![]()
They are reference parameters. The way he is passing them is correct.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.
What on earth is C++'s "True Form"?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...An effective programmer will make use of the best of Qt as a library and use standard C++.
Good advice, but the OP hardly needs comments for the little snippet that he posted.8. comment your code!!
@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.
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.Originally Posted by nupul
Save yourself some pain. Learn C++ before learning Qt.
nupul (13th April 2006)
true form...hmmm...i dunno how to put it, lets say he doesn't use qt at all in it!Originally Posted by Chicken Blood Machine
but what you said is technically correct...i'll remember that!
It'd just help someone understand...why he's doing whatever he wishes to do...no matter how small the code!Good advice, but the OP hardly needs comments for the little snippet that he posted.
Bookmarks