18
votes
Accepted
Merits of copy-on-write semantics
Copy on write is used in situations where you very often will create a copy of the object and not modify it. In those situations, it pays for itself.
As you mentioned, you can pass a const object, ...
14
votes
Accepted
Why is threading platform-dependent?
The book you are reading was published in 2007. The C++ API for managing threads wasn't standardised until 2011. At the time, on different systems you had to use entirely different platform-specific ...
12
votes
Moving from Qt/C++ to C#/WPF - Productivity Gain?
Two years later, I'll add an answer myself. This purely reflects my own experience, but might help others in the same situation.
Due to cross-platform availability, I didn't move to C#/WPF but rather ...
12
votes
Accepted
In c++, is there a way inside a function block, to execute cleanup code after the value has been returned?
Addressing the question about cleanup code:
yes, there is a way,
it's called RAII (for Resource Acquisition Is Initialization, an acronym whose limpid clarity is rivalled only by CRTP), and
it is ...
11
votes
Moving from Qt/C++ to C#/WPF - Productivity Gain?
I don't have any experience with QT, but I spent over a decade working with C++ and MFC. I now have almost a decade working with C# and WPF.
I find that I am an order of magnitude more productive in ...
11
votes
Accepted
Moving from Qt/C++ to C#/WPF - Productivity Gain?
I have significant experience with C++ UI development, mostly in Qt but also including wxWidgets and raw win32. I've also done some C# UI development in WPF.
I would strongly recommend literally any ...
9
votes
Accepted
Remove duplicated switch statements caused by not knowing type at compile time of opencv matrix?
Well, if you have the same kind of code multiple times, meaning switch on type-code and then use identical code with that type, how about using a template and generic lambda?
template <class F>...
8
votes
Accepted
I want to overload a function with the same type parameter; what should I do?
What about creating a class to hold your arguments? This class would contain both open and close parameters and either of them could be NULL. Then, there will be only one strip method with above class ...
8
votes
What can I infer from someones code when they use direct initialization with Curly Braces as opposed to Parenthese?
This shows that the author is using modern C++ (e.g. >= C++11) and applies good practice:
Braced initialization is the most widely usable initialization syntax,
it prevents narrowing conversions ...
6
votes
Accepted
Creating a private in-house application with Qt
Use of a software internally is not considered a conveyance by the GPL, so you wouldn't have to give source code to anyone.
The moment you decide to distribute your software to any third party, then ...
6
votes
Accepted
Passing by refernce
Under the hood, it might be implemented differently, but the visible effect of
MyClass(const QByteArray & raw){
this->m_rawData =raw;
}
will be that the contents of raw get copied ...
6
votes
Accepted
Is hardware accelerated GUI data kept on the GPU
Saving the whole window as a single object into GPU (it would be bunch of rectangles saved as VBO) and then rendering it in a single OpenGL draw call would be fast, but it has several disadvantages:
...
5
votes
I want to overload a function with the same type parameter; what should I do?
There are many options, it's your tradeoff which to take:
Decision at runtime:
Add a defaulted bool argument:
QString MyClass::strip(QRegularExpression regex, bool close=false);
// Mimic the two-...
5
votes
How to handle custom metadata in XML?
Besides the fact it is a very bad idea to parse XML by regular expressions, I try to answer your questions:
Was XML designed to handle custom metadata?
XML is designed to handle all kind of data ...
5
votes
Accepted
In Qt or C++, is there a good means for creating a switch with dynamically generated cases, or should I just use a for loop (or something else)?
In C++11 or better you could consider using a map of lambdas, e.g.
std::map<unsigned, std::function<void(void)> actmap;
You'll fill it dynamically, e.g.
unsigned num = somenumber();
...
5
votes
Accepted
When writing a Qt application is good practice to ALWAYS prefer Qt function implementations, data types, and classes when they are available?
If there is an exact equivalent in the C++ standard (like for exact-width types, or math functions), you loose portability to any project not using QT, without gaining anything. And people might ...
5
votes
Accepted
How to understand and design functions with enumeration arguments that work in tandem with bitwise operators in C++ and Qt?
Your understanding is pretty good. To answer your questions:
Yes, it the function will receive 0x0000 0000 0000 0000 0000 1010 as an argument.
The significance of the decimal number 10 in binary is ...
5
votes
Accepted
Should I always allocate QObject and derived classes to the heap?
The motivation for not putting QObjects on the stack is the Qt ownership model. If an object is destroyed all of its child objects are automatically deleted. If one of those child objects is allocated ...
5
votes
fake filesystem for unit tests
The only thing which comes to my mind is to create needed file structure in a temporary directory and work on it, but that's not a perfect solution
Did you try it? This solution works well for many ...
4
votes
I want to overload a function with the same type parameter; what should I do?
I would suggest
QString MyClass::strip();
QString MyClass::strip(QRegularExpression regex, bool opening=false);
QString MyClass::strip(QRegularExpression open, QRegularExpression close);
and ...
4
votes
Why is threading platform-dependent?
... threading is platform-dependent, can someone explain, why?
The platform dependencies are typically differences in the way that the thread scheduler works. The fact is that thread schedulers do ...
4
votes
Is it good practice to have your C++/Qt functions always check all its arguments for null values?
As I commented, yes you should usually check against nullptr and always document if a public function accepts a null pointer or not (that it, document a function as accepting a null pointer, or as ...
4
votes
How to treat in-house libraries
To adress these problems one by one:
check out multiple repositories
Using SVN, you can utilize the "externals" feature for this. This will allow you to define dependencies between different repos ...
4
votes
Accepted
How to facilitate thread-safe access to large set of shared variables?
Comments turned into an answer:
You are right to worry about performance with locking everything under one mutex, but the better solution is to make sure there is as little going on as possible ...
4
votes
Accepted
What is the proper way to track my build versions in Qt?
Proper way is:
Have (any possible) Version Control in your project (and forever for all projects)
Instead of rather useless autoincremented counter use any id, provided by VCS of choice
Get this id ...
4
votes
In Qt or C++, how should I check whether my `int` variable has been defined?
The best solution would be to avoid the possibility to ever have an uninitialized integer, by passing the value with the constructor.
This way the user of your class is forced to pass a value if he ...
4
votes
Accepted
How should I structure my C++ project to allow for starting, stopping, and pausing my program?
If it's understood that pauses don't take effect until the current action is finished, then the other parts of the program shouldn't care what the start/stop/pause condition is. They do nothing until ...
4
votes
Moving from Qt/C++ to C#/WPF - Productivity Gain?
I've been shared between WPF, Qt, JavaFX years ago, and chose WPF/c#/XAML/MVVM and find it very fast to develop, excellent to maintain, powerful in terms of possibilities and performance; it relies on ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
qt × 115c++ × 65
gui × 13
python × 9
lgpl × 8
design × 7
multithreading × 7
design-patterns × 6
architecture × 6
programming-practices × 6
licensing × 6
coding-style × 6
mvc × 6
pointers × 5
performance × 4
gpl × 4
programming-languages × 3
android × 3
event-programming × 3
switch-statement × 3
pyqt4 × 3
java × 2
object-oriented × 2
algorithms × 2
unit-testing × 2