c++

How to use gprof to profile a daemon process without terminating it gracefully?

Need to profile a daemon written in C++, gprof says it need to terminate the process to get the gmon.out. I'm wondering anyone has ideas to get the gmon.out with ctrl-c? I want to find out the hot spot for cpu cycle ...

Create a desktop widget (gadget) with QT 4

How do I create with QT 4 a window that remains anchored to the desktop as a widget ? (Eg like Yahoo Widgets or Google Gadgets). I intend to give the same characteristics of a widget to a normal window: Remove the edges (easy to do) The window must not move (how ?) Must be displayed only when other windows are minimized (how ?) ...

how to interpret a freetype glyph outline when the first point on the contour is off curve

I'm actually working on a renderer that converts freetype glyphs into polylines to control a laser marking system. The problem I have is that I don't know how to handle correctly a contour beginning with an off curve point (99.9% begin with on curve points!). I've searched quite a while now for informations but I couldn't find anything u...

What is the right way to typedef a type and the same type's pointer?

What is the right way to typedef a type and the same type's pointer? Here is what I mean. Should I do this: typedef unsigned int delay; typedef unsigned int * delayp; Or should I do this: typedef unsigned int delay; typedef delay * delayp; Or perhaps I should not typedef pointer at all and just use delay * instead of delayp everywh...

What is the right way to allocate memory in the C++ constructor?

Which is the right way to allocate memory via new in the C++ constructor. First way in the argument list: class Boda { int *memory; public: Boda(int length) : memory(new int [length]) {} ~Boda() { delete [] memory; } }; or in the body of constructor: class Boda { int *memory; public: Boda(int l...

What is better way to loop over two ranges - multiply them together and do it one loop, or loop over each range separately?

I can't decide how I should loop over ranges. This way: for (int i = 0; i < max_i; i++) { for (int j = 0; j < max_j; j++) { // first way - two loops } } Or this way: for (int k = 0; k < max_i*max_j; k++) { // second way - one loop } Thanks, Boda Cydo. ...

How can i find the QModelIndex for given composite primary key, with QSqlTableModel

I have this table QSqlQuery createTblSMS("CREATE TABLE sms_tbl(" "isRead BOOLEAN NOT NULL," "readTime DATETIME," "arrivalTime DATETIME NOT NULL," "sender TEXT NOT NULL," "receiver TEXT NOT NULL," "smsContent TEXT," "PRIMARY KEY(arrivalTime, sender, ...

Render to FBO not working, gDEBugger says otherwise

I'm trying to render to a texture using an FBO. When trying to do so, gDEBugger shows the correct texture, but when drawing it on a quad its just "white" / the glColor4f. Here is the code to create the texture, fbo and renderbuffer: glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEX...

Inherited method with different type

i have something like this class A { virtual void doBla(A *a) = 0; }; class B : public A { virtual void doBla(B *b) { // do stuff ;}; }; and i want to do something like A* a = new B(); B* b = new B(); a->doBla(b); or: all children of A are supposed to have a method doBla which takes a parameter of the type of the child. ...

Explain any one method by which c++ implements polymorphism

Explain any one method by which c++ implements polymorphism....... ...

Getting the same memory again and again

Hi In my program I am creating an object of a class in a loop and storing it in a vector. Then I print the address of the object and the member variable. After that I erase them . I see that every time I see the same address assigned to my object and the member variable which is a pointer. Can any one explain this behavior. #include ...

Get current item from QMutableListIterator

I can't dereference a QMutableListIterator like an STL iterator - with *it. I'm trying to use QMutableListIterator::value() but my program crashes. What is the right way to do this? QFileInfoList files; // populate list QListIterator<QFileInfo> it(files); it.toFront(); QFileInfo = it_top.value(); // crash The error is ASSERT: "item...

preventing boost from making a copy of a my callback handler

I wrote a small tcp client using boost::asio, providing the following function: typedef boost::function<void(const bs::error_code& errCode, size_t bytesTransferred)> ReadHandler; void CTcpClient::AsyncRead2(std::vector<char>& data, size_t length, ReadHandler readCompletedCallback) { async_read(m_tcpData->socket, ba::buffer(data, le...

Correctly getting sha-1 for files using openssl

Hi I am trying to get an sha-1 for a number of files. What I currently do is cycle the files in a given path, open and read each file separately and load the contents in a buffer and then send it to openssl's SHA function to get the hash. The code looks something like this: void ReadHashFile(LPCTSTR name) { FILE * pFile; long lSi...

Is there an intelligent way to know the name of the library to link to at compile time? (Linux/Kubuntu)

Please bear with me. I really want to know as I am curious about the answer: Is there an intelligent way to know the name of the library to link to at compile time? Allow me to give you an example that illustrates perfectly the reason for my question. I am a C++ newbie. I am learning about compiling, linking and libraries like boost. ...

Books about C(C++) with the idea of porting apps from C to Java

Could you recommend me some books on C and C++, that would be suitable for a Java developer? In JAVA most things look simple enough, and the Specification helps a lot but both C and C++ are full of features that make me dizzy. Not that I have absolutely no experience with C++, but it's far from enough. I am especially interested in C bo...

Direct call using GCC's inline assembly

If you want to call a C/C++ function from inline assembly, you can do something like this: void callee() {} void caller() { asm("call *%0" : : "r"(callee)); } GCC will then emit code which looks like this: movl $callee, %eax call *%eax This can be problematic since the indirect call will destroy the pipeline on older CPUs. Sin...

Can I trick access to private C++ class member variables?

Possible Duplicate: Accessing private members Is it possible to access private members of a class? Is there a good (yes I know this is ugly) way to hack to the private data members of a class? One brute force approach is to copy the header file and in my copy change private to public. But would there be a better way, say doi...

Where can I find a good Scope Guard implementation for my C++ projects?

I just recently learned about Scope Guard C++ idiom. Unfortunately I can't find any good implementation of it. Can anyone point me to some good and usable Scope Guard implementation in C++? Thanks, Boda Cydo. ...

validating the value in a integer...????

how do v find a value in an integer is garbage or not??? ...