c++

PyQt: how to handle auto-resize of widgets when their content changes

I am having some issues with the size of qt4 widgets when their content changes. I will illustrate my problems with two simple scenarios: Scenario 1: I have a QLineEdit widget. Sometimes, when I'm changing its content using QLineEdit.setText(), the one-line string doesn't fit into the widget at its current size anymore. I must select ...

Unresolved External Symbol

I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#. I have the .lib files linked in and everything has been going smoothly so far. Upon wrapping the latest .h file, I hit a snag when 2 functions came back with the link error: error LNK2019: unresolved...

message order incorrect (using io_service::wrap)

Hi! I've an application to which a GUI connects and receives a lot of messages and the problem is that every once in a while it receives a message out of order. The connection runs on a separate worker thread (a separate io_service) and exposes the "send" function(which does a async__write) via io_service::wrap as a callback for others...

Using VB for Artificial Intelligence

Do you think VB is a good language for AI? I originally did AI using mainly Lisp and C/C++ when performance was needed, but recently have been doing some VB programming. VB has the following advantages: 1. Good debugger (essential!) 2. Good inspector (watch facility) 3. Easy syntax (Intellisense comparable to structure editors of late 8...

USB Communication API

Is there a decent USB communication API? Preferably cross-platform (Linux if not, I guess) I don't have a specific use in mind, I just want to learn about using the USB ports for future electronics projects. I realize this is very general, I'll try to refine the question as the answers point me in the right direction. Thanks. ...

C++ Socket programming Windows

Hi I wanna set up a socket on a windows machine. For compilation I am using cygwin with the g++ compiler. For setting up a socket I would need the following library: WS2_32.lib which cannot be found on my machine. Is this part of MS SDK or can I download it for free from the web somewhere? If not, is there another way to setup a Socke...

How could I print the contents of any container in a generic way ?

I am trying to write a piece of code for fun using C++ templates. #include <iostream> #include <vector> template <class Container> std::ostream& operator<<(std::ostream& o, const Container& container) { typename Container::const_iterator beg = container.begin(); o << "["; // 1 while(beg != container.end()) { o <<...

Why are doubles added incorrectly in a specific Visual Studio 2008 project?

Trying to port java code to C++ I've stumbled over some weird behaviour. I can't get double addition to work (even though compiler option /fp:strict which means "correct" floating point math is set in Visual Studio 2008). double a = 0.4; /* a: 0.40000000000000002, correct */ double b = 0.0 + 0.4; /* b: 0.40000000596046448, incorrect (0...

Is there an operating system API wrapper library for c++?

Hi SO-followers, does sombebody know a C++ library for accessing different operating system APIs? I'm thinking about a wrapper to access OS specific functions. Something like: osAPI.MessageBox(); // calls MessageBox() in Win32, equivalent in Mac OS Linux etc... Since I think it's hard to realize this for different OSes for now it wou...

How to store and call a compiled function in C / C++?

For very low level optimization purposes it would be useful to me if I could store a compiled function inside a variable directly, not a pointer to a function. That is, if I have a function foo, I want to make a char buffer large enough to hold the machine instructions generated for foo, and then be able to in effect call foo by somehow ...

loading managed resources from c# and passing it to Native CPP code as a stream handle

I have a file that I have embedded as a resource in a managed C# assembly. I would like to pass the pointer to that resource and its size to some native code so it can extract it for me if needed. Are there C# api's that give me the intptr of that embedded resource? ...

C++ Compiler For Windows

Hello, I'm using Windows Vista Ultimate and i want to know what is the best C++ compiler for my Windows, because in Linux i use in somee cases gcc and in others g++, but recently i've installed Windows in my computer and this is the question: What is the best C++ compiler for Windows? Thanks! ...

String memory management during the assignment stored in the map

I have a string and I would like to put a reference to that string into a map. string m_tmp; map<pair<string, string>, string&> m; m[pair<string, string>("Foo","Bar")]= m_tmp; then, I change the m_tmp; m_tmp="DFDFD"; Will the map (on all conforming platforms) still reference m_tmp with a new value? According to the dummy program bel...

line drawing routine

How to optimize this line drawing routine ? Will memcpy work faster ? void ScreenDriver::HorizontalLine(int wXStart, int wXEnd, int wYPos, COLORVAL Color, int wWidth) { int iLen = wXEnd - wXStart + 1; if (iLen <= 0) { return; } while(wWidth-- > 0) { COLORVAL *Put = mpScanPointers[wYPos] + wXS...

Loading a C/C++ compiler in Linux.

Hi all, Recently i had installed the UBUNTU flavour of the Linux operating system.I had opened a terminal and just wrote a sample C programm to check if it is compiling.When i saved the sample file and compiled with cc a.c ,errors comes that the standard library is not loaded(i.e stdio.h>.When i went to help pages,it says that the...

Kill self if hWnd doesn't exist

I have a c++ console application that launches another application and communicates with it via com. I have the spawned window's hWnd and I want the console app to kill itself if the COM app is no longer open. How could I go about doing this? ...

void* to Object^ in C++/CLI

I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#. Some of the native C++ functions have a return type of void*. I am not sure how to handle this when I pass back the value to my calling code. For instance: if a C# app calls my dll wrapper, what do I ...

C++0x will no longer have concepts. Opinions? How will this affect you?

At the July 2009 C++0x meeting in Frankfurt, it was decided to remove concepts from C++0x. Personally, I am disappointed but I'd rather have an implementable C++0x than no C++0x. They said they will be added at a later date. What are your opinions on this decision/issue? How will it affect you? ...

Load binary file using fstream

I'm trying to load binary file using fstream in the following way: #include <iostream> #include <fstream> #include <iterator> #include <vector> using namespace std; int main() { basic_fstream<uint32_t> file( "somefile.dat", ios::in|ios::binary ); vector<uint32_t> buffer; buffer.assign( istream_iterator<uint32_t, uint32_t>...

Why do I get an error in "forming reference to reference type" map?

What is the alternative if I need to use a reference, and the data I am passing I cannot change the type of, hence I cannot really store a pointer to it? Code: #include <map> #include<iostream> #include<string> using namespace std; int main() { string test; pair<string, string> p=pair<s...