c++

Qt QMainWindow at Close

Hey, this may seem like a very simple question, but I want to dump some data whenever the QMainWindow closes, so I used the following piece of code: QObject::connect(MainWindow.centralwidget, SIGNAL(destroyed()), this, SLOT(close())); but this doesnt seem to make it call close(). Am I doing this wrong? Isnt the centralwidget suppos...

How do I install the OpenSSL C++ library on Ubuntu?

I'm trying to build some code on Ubuntu 10.04 LTS that uses OpenSSL 1.0.0. When I run make, it invokes g++ with the "-lssl" option. The source includes: #include <openssl/bio.h> #include <openssl/buffer.h> #include <openssl/des.h> #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/rsa.h> I ran: $ sudo apt-get insta...

Non-Linear color interpolation?

If I have a straight line that mesures from 0 to 1, then I have colorA(255,0,0) at 0 on the line, then at 0.3 I have colorB(20,160,0) then at 1 on the line I have colorC(0,0,0). How could I find the color at 0.7? Thanks ...

How to pass a function in a function?

That's an odd title. I would greatly appreciate it if somebody could clarify what exactly I'm asking because I'm not so sure myself. I'm watching the Stanford videos on Programming Paradigms(that teacher is awesome) and I'm up to video five when he started doing this: void *lSearch( void* key, void* base, int elemSize, int n, int (*cmp...

Obtain container type from (its) iterator type in C++ (STL)

It is easy given a container to get the associated iterators, example: std::vector<double>::iterator i; //An iterator to a std::vector<double> I was wondering if it is possible, given an iterator type, to deduce the type of the "corresponding container" (here I am assuming that for each container there is one and only one (non-const) ...

Interaction between for loops with clock function?!

Can someone explain me the exact interaction in context of delay between the two for loops with clock function. How does for1 interact with for2 on the cout statement(30 on 640000000)? start=clock(); cout<<endl<<start<<endl; for(delay=0; delay<30; delay++) for(i=0; i<640000000; i++); end=clock(); cout<<end<<endl; cout<<"Num of tick...

How to get total cpu usage in Linux (c++)

I am trying to get total cpu usage in %. First I should start by saying that "top" will simply not do, as there is a delay between cpu dumps, it requires 2 dumps and several seconds, which hangs my program (I do not want to give it its own thread) next thing what I tried is "ps" which is instant but always gives very high number in tota...

How to handle asynchronous socket receiving in C++?

I'm currently using a thread to handle Connect and Send calls asynchronously. This is all working fine, but now I want to make receiving asynchronous too. How should I receive data without pausing the whole queue while waiting for data? The only solution I can think of right now is a second thread. ...

How to expose a function in an exe to Python using SWIG without creating a dll (.pyd)?

I got a prototype working of exposing C++ classes & methods to python using SWIG. I had to create a DLL (.pyd) of the classes/members I want to expose (_MyModule.pyd & MyModule.py). But now I want to expose classes/members/functions in the exe. How to do this? Refactoring the exe is not an option. One way is to create a wrapper dll fo...

How to Validate an XML Node against an XSD in C++?

Hi Please note that I'm asking for validation against a particular node and not the whole file. For examples <somexmldoc> <someNode> <UserDefinedNode> </> <UserDefinedNode> </> </someNode> </somexmldoc> For this XML doc, I have an wholeDoc.XSD which could be used to validate the whole document except "UserDef...

C++: Is it good practice to make getters and setters inline?

Hi, The title says it all. public: inline int GetValue() const { return m_nValue; } inline void SetValue(int nNewValue) { this -> m_nValue = nNewValue; } On Learn C++, they said it would run faster. So, I thought it would be great. But maybe, there are some negative points to it. ...

Reading and writing to SysV shared memory without synchronization (use of semaphores, C/C++, Linux)

Hi, I use SysV shared memory to let two processes communicate with each other. I do not want the code to become to complex so I wondered if I really had to use semaphores to synchronize the access to the shared memory. In my C/C++ program the parent process reads from the shared memory and the child process writes to the shared memory. ...

Question about my sorting algorithm in C++

i have following code in c++ #include <iostream> using namespace std; void qsort5(int a[],int n){ int i; int j; if (n<=1) return; for (i=1;i<n;i++) j=0; if (a[i]<a[0]) swap(++j,i,a); swap(0,j,a); qsort5(a,j); qsort(a+j+1,n-j-1); } int main() { return 0; } void swap(int i,in...

Why does this class declaration not work on Visual Studio

So I'm trying to get some code that is written for gcc to compile on Visual Studio 2008. I have a problem that I have narrowed down to this: class value_t { public: typedef std::deque<value_t> sequence_t; typedef sequence_t::iterator iterator; }; This code fails: 1>cpptest.cpp 1>c:\program files\microsoft visual st...

opencv conversion from a Mat element to IplImage *

How can I convert a Mat element to IplImage * element? Please Help! ...

how can i use youtube chromeless player in desktop application ?

Hello all i like to use youtube chromeless player in my QT c++ application im using qwebkit , but in the youtube doc's its says: " To test any of these calls, you must have your file running on a webserver...." how can i overcome this restriction and use chromeless player or some alternative? ...

which is the cleaner way to do this simple while?

I'm learning C++ and I want to make clean and readable code. I was wondering which way is better? (this is supposed to make the factorial of 9) First Method: int main(){ int i = 1,r = i; while (i < 10) { r *= ++i; } } Second Method: int main(){ int i = 1,r = i; while (i < 10) { i++; r *= i ...

OpenGL: How to update only a portion of a texture?

I dont want to update the whole texture every time i change a small part of it, what is the command for this? And when i have mipmapping on, set with GL_GENERATE_MIPMAP, how optimized is that internally? will it calculate whole image again, or just the part i updated? ...

Given Date, Get Day of Week - SYSTEMTIME

Is it possible to determine the day of the week, using SYSTEMTIME, if a date (month-day-year) is provided or is this structure one-way only? What is the most lightweight way to accomplish what I am asking if SYSTEMTIME cannot do it (using Win32)? ...

check compiler version in visual studio 2008

Hello, Im writing application in c++ and after try to run built (in debug mode) application on another machine I had error (The application has failed to start because its side-by-side configuration is incorect). I realised that there are missed DLLs from windows\WinSxS\ But I dont really know which folder contains what I really need ...