How to draw a point (on mouseclick) on a QGraphicsScene?

UPDATE: There is a new class called QGraphicsSceneMouseEvent that makes this a little easier. I just finished an example using it here: https://stackoverflow.com/a/26903599/999943 It differs with the answer below in that it subclasses QGraphicsScene, not QGraphicsView, and it uses mouseEvent->scenePos() so there isn’t a need to manually map coordinates. You are on the right track, … Read more

How do I get crtdbg.h file?

I ran into this exact same issue, but with Visual Studio Community Edition 2019. The solution was to download the Windows 10 SDK using the Visual Studio installer. Once I did that the next compile worked fine. The header file “crtdbg.h” is part of the Windows 10 SDK kit. I believe you will find crtdbg.h … Read more

Howto: c++ Function Pointer with default values

Function pointers themselves can’t have default values. You’ll either have to wrap the call via the function pointer in a function that does have default parameters (this could even be a small class that wraps the function pointer and has an operator() with default paremeters), or have different function pointers for the different overloads of … Read more

How can I find the size of all files located inside a folder?

How about letting OS do it for you: long long int getFolderSize(string path) { // command to be executed std::string cmd(“du -sb “); cmd.append(path); cmd.append(” | cut -f1 2>&1″); // execute above command and get the output FILE *stream = popen(cmd.c_str(), “r”); if (stream) { const int max_size = 256; char readbuf[max_size]; if (fgets(readbuf, max_size, … Read more

Convert a C++ program to a Windows service?

There’s a good example on how to set up a minimal service on MSDN. See the parts about writing the main function, entry point and also the example code. Once you’ve got a windows service built and running, you’ll discover the next major gotcha: it’s a pain to debug. There’s no terminal (and hence no … Read more

should std::common_type use std::decay?

should std::common_type use std::decay? Yes, see Library Working Group Defect #2141. Short version (long version, see link above): declval<A>() returns a A&& common_type is specified via declval, n3337: template <class T, class U> struct common_type<T, U> { typedef decltype(true ? declval<T>() : declval<U>()) type; }; common_type<int, int>::type therefore yields int&&, which is unexpected proposed resolution … Read more

true isometric projection with opengl

Try using gluLookAt glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* use this length so that camera is 1 unit away from origin */ double dist = sqrt(1 / 3.0); gluLookAt(dist, dist, dist, /* position of camera */ 0.0, 0.0, 0.0, /* where camera is pointing at */ 0.0, 1.0, 0.0); /* which direction is … Read more