c++

swig: How to make a QList<T> iterable, like std::vector

拈花ヽ惹草 提交于 2021-02-19 02:39:10
问题 I'm using SWIG to generate Python Bindings for my qt app. I have several places where I use QLists and I would like to integrate those QLists like std::vector from the SWIG Library (see http://www.swig.org/Doc1.3/Library.html#Library_nn15). This means: The QList objects should be iterable from python (= they must be an iterable python object) It should be possible to pass a python list to a function which takes a qlist ... and all the other features listed in the SWIG Library for std::vector

Why does the map.insert() method invoke the copy constructor twice?

匆匆过客 提交于 2021-02-19 02:39:08
问题 I'm creating the custom class Node in order to implement a binary tree using a map<int,Node> container: the int key of the map is the identifier of a Node object. In the class Node I had to implement a copy constructor. When inserting a Node object on the map, I noticed that the copy constructor of the Node is invoked twice. Why? cout << "node2" << endl; Node node2; node2.set_depth(2); node2.make_it_branch(3,4); cout << "map" << endl; map<int,Node> mapping; cout << "toInsert" << endl; pair

scope of std::lock_guard inside if block

一个人想着一个人 提交于 2021-02-19 02:37:39
问题 Currently studying about std::mutex and would love some help. If I've a code that looks like - .... if(returnBoolValue()) { std::lock_guard<std::mutex> lock(mutex_var); .... .... } .... is the std::lock_guard guarding the function returning the value inside if condition? ie. returnBoolValue() And how should I improve it so that function call is inside the guard as well, if possible? std::mutex - http://en.cppreference.com/w/cpp/thread/mutex std::lock_guard - http://en.cppreference.com/w/cpp

How to remove last argument of variadic template

北城余情 提交于 2021-02-19 02:28:06
问题 I have following structure, I want remove last argument from index_sequence : template< std::size_t ... values> struct index_sequence{}; // I need something like template< typename IndexSequence> struct pop_back; template< std::size_t ... values > struct pop_back< index_sequence< values... > > { typedef index_sequence< /** values except last one*/ > type; }; How to implement this pop_back structure? I know implementation, only it requires deep recursion, I want without deep recursion

C++/OpenCV - Kalman filter for video stabilization

邮差的信 提交于 2021-02-19 02:25:08
问题 I try to Stabilize video with a Kalman filter for smoothing . But i have some problems Each time, i have two frames: one current and another one. Here my workflow: Compute goodFeaturesToTrack() Compute Optical Flow using calcOpticalFlowPyrLK() Keep only good points Estimate a rigid transformation Smoothing using Kalman filter Warping of the picture. But i think there is something wrong with Kalman because at the end my video is still not stabilized and it's not smooth at all, it even worse

C linkage function cannot return C++ class - error resulting from the contents of my method

你说的曾经没有我的故事 提交于 2021-02-19 02:23:42
问题 I am exporting a method that can be called from unmanaged code, but the function itself lives in a managed c++ project. The following code results in a compiler error: error C2526: 'System::Collections::Generic::IEnumerator<T>::Current::get' : C linkage function cannot return C++ class 'System::Collections::Generic::KeyValuePair<TKey,TValue>' error C2526: 'System::Collections::Generic::Dictionary<TKey,TValue>::KeyCollection::GetEnumerator' : C linkage function cannot return C++ class 'System:

C linkage function cannot return C++ class - error resulting from the contents of my method

≡放荡痞女 提交于 2021-02-19 02:23:21
问题 I am exporting a method that can be called from unmanaged code, but the function itself lives in a managed c++ project. The following code results in a compiler error: error C2526: 'System::Collections::Generic::IEnumerator<T>::Current::get' : C linkage function cannot return C++ class 'System::Collections::Generic::KeyValuePair<TKey,TValue>' error C2526: 'System::Collections::Generic::Dictionary<TKey,TValue>::KeyCollection::GetEnumerator' : C linkage function cannot return C++ class 'System:

Preventing implicit conversion operator only for binary operators

走远了吗. 提交于 2021-02-19 02:22:09
问题 I'm having an issue that I've boiled down to the following, where an == operator usage compiles even though it's supposed to fail (C++17, tested on GCC 5.x, 8.x, and 9.x): template <int N> struct thing { operator const char * () const { return nullptr; } bool operator == (const thing<N> &) const { return false; } }; int main () { thing<0> a; thing<1> b; a == b; // i don't want this to compile, but it does } The reason it is compiling is because the compiler is choosing to do this: (const char

Qt: QWidget::paintEngine: Should no longer be called

最后都变了- 提交于 2021-02-19 01:59:07
问题 I'm trying to make an app where you can draw with your finger on a canvas. To achieve this, I'm subclassing QWidget as MFCanvas , registered the class in QML with qmlRegisterType<>() , implementing the virtual paintEvent(); function, and drawing on it with a QPainter inside the paintEvent(); function. The Problem: Upon construction, the QPainter throws this warning: QWidget::paintEngine: Should no longer be called Then, serveral other related warnings are thrown: QPainter::begin: Paint device

Saving a simple image buffer to png in C++

僤鯓⒐⒋嵵緔 提交于 2021-02-19 01:52:10
问题 I'd like to do this in a platform independant way, and I know libpng is a possibility, but I find it hard to figure out how. Does anyone know how to do this in a simple way? 回答1: There is a C++ wrapper for libpng called Png++ . Check it here or just google it. They have a real C++ interface with templates and such that uses libpng under the hood. I've found the code I have written quite expressive and high-level. Example of "generator" which is the heart of the algorithm: class PngGenerator :