c++

Submitting QSqlRecord to MySQL database in Qt

I want to access a MySQL database and I want to read+write data from+to the database within my Qt/C++ program. For the read write process, I try to use QSqlTableModel, QSqlTableRcord and QSqlDatabase as this is a very pleasant approach without too much of SQL commands which I dislike for the one or other reason (to handle myself). I got ...

Explicit Address Manipulation in C++

Please check out the following func and its output void main() { Distance d1; d1.setFeet(256); d1.setInches(2.2); char *p=(char *)&d1; *p=1; cout<< d1.getFeet()<< " "<< d1.getInches()<< endl; } The class Distance gets its values thru setFeet and setInches, passing int and float arguments respectively. It dis...

Is Winforms accessible from unmanaged C++?

Some classic Windows/C++ applications can't easily be moved to managed C++.net, due to use of external libraries. Is it feasible to use newer GUI libraries like winforms (or even WPF) with such applications, 'dropping in' new controls to replace stale-looking MFC? Or is it not really worth it, and would take a lot of time? ...

variables scoping when inheriting

I have two classes in C++, where one inherits from the other: class A { public: virtual void Initialize(){ m_MyString = "Default value"; } protected: string m_MyString; } class B : public A { public: void Initialize(){ A::Initialize(); m_MyString = "New Value"; } } Is there a differenc...

Templates: template function not playing well with class's template member function

This is a minimal test case of some code that I actually have. It fails when it tries to evaluate a.getResult<B>(): test.cpp: In function 'void printStuff(const A&)': test.cpp:6: error: expected primary-expression before '>' token test.cpp:6: error: expected primary-expression before ')' token The code is: #include <iostream> templa...

What's the most efficient way to do recursive XPath queries using libxml2?

I've written a C++ wrapper function for libxml2 that makes it easy for me to do queries on an XML document: bool XPathQuery( const std::string& doc, const std::string& query, XPathResults& results); But I have a problem: I need to be able to do another XPath query on the results of my first query. Currently I do this by s...

Best way to port MFC COM Server to Managed code

Hi all, I am working on an application suite comprising of multiple Automation servers written using MFC and this is legacy code. These apps inter communicate via COM interfaces and other events. Most of these apps provide multiple form views with various input controls to capture information. I was wondering what would be the best way ...

Iterating over subsets of any size

I can iterate over the subsets of size 1 for( int a = 0; a < size; a++ ) { or subsets of size 2 for( int a1 = 0; a1 < size; a1++ ) { for( int a2 = a1+1; a2 < size; a2++ ) { or 3 for( int a1 = 0; a1 < size; a1++ ) { for( int a2 = a1+1; a2 < size; a2++ ) { for( int a3 = a2+1; a3 < size; a3++ ) { But how to do this for subse...

LZMA SDK Progress

Hi, In my application, I'm compressing ~400Mb of data with LZMA SDK. Naturally, this takes some time. Even after massive Googling, I wasn't able to find any information how to get live progress information of the compress-process. Is this done with some callback function or what? Thanks in advance, nhaa123 ...

Convert std::vector<char*> to a c-style argument vector arv

I would like to prepare an old-school argument vector (argv) to use within the function int execve(const char *filename, char *const argv[],char *const envp[]); I tried it with the stl::vector class: std::string arguments = std::string("arg1"); std::vector<char*> argv; char argument[128]; strcpy(argument, arguments.c_str()...

C++ My form should stay on top of every kind of windows

Hi, I have a main form. This main form generate another form. This new form should be fill before having access to other window. I used Myform.ShowDialog() to make this form modal. I would like that my form will be on top of every type of other windows even if these windows are not part of my application (for example: Internet explore...

How to make two arrays into a function in c++?

I have two string arrays "Array1[size]" and "Array2[size]". They both have the same size. I would like to write a function which contains this two arrays but I am having problems in the way that I am declaring them. I am declaring it like this: void Thefunction (string& Array1[], string& Array2[], int size); And when I call it I am...

HttpSendRequest blocking when more than two downloads are already in progress

In our program, a new thread is created each time an HTTP request needs to be made, and there can be several running simultaneously. The problem I am having is that if I've got two threads already running, where they are looping on reading from InternetReadFile() after having called HttpSendRequest(), any subsequent attempts to call Htt...

C++ nil vs NULL

OK, I have some C++ code in a header that is declared like this: void StreamOut(FxStream *stream,const FxChar *name = nil); and I get: error: 'nil' was not declared in this scope nil is a pascal thing, correct? Should I be using NULL? I thought they were both the same or at least Zero, no? ...

Where is Boost.Process?

I need to execute a program and retrieve its stdout output in c++. I'd like my code to be cross-platform too. Having recently discovered the wonderful world of the Boost c++ libraries for all your cross platform needs, I figured I'd just go to boost.org and read up on the documentation of Boost.Process. Much to my surprise, it wasn't th...

C++ compilation error using string and istream_iterator

When trying to compile the following: #include <string> #include <iterator> #include <iostream> using namespace std; int main() { string s(istream_iterator<char>(cin), istream_iterator<char>()); return s.size(); } g++ 4.4.1 gives me: main.cc: In function ‘int main()’: main.cc:6: error: request for member ‘size’ in ‘s’, which is o...

Heap fragmentation and windows memory manager

Hi, I'm having trouble with memory fragmentation in my program and not being able to allocate very large memory blocks after a while. I've read the related posts on this forum - mainly this one. And I still have some questions. I've been using a memory space profiler to get a picture of the memory. I wrote a 1 line program that conta...

Why does the map size returns 0

using namespace std; class A { public: A() {} ~A() {} map<int, string*>& getMap() { return mapStr; } void setMap(const map<int,string*> m) { mapStr = m; } private: map <int, string*> mapStr; }; class B { public: ...

C++ compiler question- resolving name of a class member

When the compiler sees this code: SomeClass foo; int x = foo.bar; What is the process it goes about in retrieving the value of bar? I.e. does it look at some data structure representing the class definition? If so is this data structure generated at compile time or runtime? ...

a very simple c++ oop question

im struggling with syntax here: hopefully this question is v simple, im just miising the point. specifically, if i nest a class within another class, so for instance class a { a //the constructor { b an_instance_of_b // an instance of class b } }; class b { public: foo() { cout << "foo"; }...