Hot answers tagged

118

As people say, each tool fits to each problem and situation... But if you're C++ programmer, Qt is your framework. No rival. We develop a complex medical imaging commercial application, and Qt holds on. I don't say that the 'cons' that people say about it are false, but I have the feeling that they don't have tried Qt for a long time (its continously ...


72

A "raw" pointer is unmanaged. That is, the following line: SomeKindOfObject *someKindOfObject = new SomeKindOfObject(); ... will leak memory if an accompanying delete is not executed at the proper time. auto_ptr In order to minimize these cases, std::auto_ptr<> was introduced. Due to the limitations of C++ prior to the 2011 standard, however, it's ...


36

If you re-write & re-design from scratch, you're going to have two MASSIVE problems: You don't have a spec. You might think you have a spec, but it turns out that the REAL spec is the old code. So you're going to have to dig into it to figure out what it really does, just so you know what to make the new system do. You'll have a long period (looking at ...


30

One reason to not use Qt is that if you only write for one architecture, such as Windows, you may want to use C#/.NET (or Cocoa on Mac) because they will invariably be able to take advantage of the latest bells-and-whistles of the OS. If you are writing cross-platform apps, then you may already be heavily vested in another technology such as Java (i.e. you ...


16

I agree with nearly all of the reasons discussed above however a lot of people here have said they wouldn't use Qt because of the extra overhead that it brings with it. I disagree with that because all the most common languages today (Java, C# and Python) carry a fair bit of overhead themselves. Secondly, Qt makes programming with C++ so easy and straight-...


15

I wouldn't refrain from using Qt just for those reasons. You are not required to use all of Qt's utility classes; for the ones that replace the STL, you'll at most be forced to use QString and, possibly, QStringList. Also, there's usually much more to a program than the GUI. You can always use exclusively generic C++ for the rest of your program, and use Qt ...


15

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, and in many cases that is sufficient. However, const only guarantees that the caller can't mutate it (unless they const_cast, of course). It does not handle ...


14

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 libraries (pthreads, win32 threads, etc). Now, this is no longer true. Your book is out of date.


13

This genuinely isn't an attempt to start a flame war, I just wanted to address some of the points. Probably the real reason that Qt isn't more widely used is that it's C++ and fewer people use c++ for desktop apps. Qt is not a C++ library. It requires a separate compilation step, which makes the build process much more complicated when compared with ...


12

I could give you some rough guidelines as to how to create the equivalent GUI for a CLI app, design-wise. How you would actually make the calls is out of the scope of this answer. switches like -p -v etc are checkboxes mutually exclusive options are a group of radio buttons parameters that are a filename are a textbox with a "choose" button that shows a ...


12

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 both idiomatic and highly recommended (eg, by the C++ Core Guidelines) You'll see there is built-in support for RAII for some common types in the form of std::...


11

ABC - ALWAYS BE CODING. It's really that simple. One of my favorite ways of getting to know a language is to write a toy interpreter for a subset of the language in the language itself or if that's not your thing then maybe a ray tracer or something else that's just big enough to be non-trivial but not so big that it can't be finished in a month or so. The ...


9

C/C++ is fast. The reality is, most apps wont need that performance with the state of the current hardwares. The usual way is to develop the application in a high level language, like python, than optimize when needed with lower level languages, like C/C++. Python will give you a big productivity boost, it's easy to learn and reasonably fast. There is ...


9

I would say you should do the contrary, a good design would be for your application to be able to run whatever its context is. That's why for every application I code, I create a CLI tool that implements the logic, and then I implement a GUI. Where am I heading to ? You're creating a MainController object that holds the world, and then modifies the Ui_Game ...


9

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> auto do_typed(int type, F f) { switch(type) { case CV_8U: return f(std::enable_if<true, std::uint8_t>()); case CV_8S: return f(std::...


8

As nicely explained in Teach Yourself Programming in Ten Years, you should follow next steps : Get interested in programming, and do some because it is fun. Make sure that it keeps being enough fun so that you will be willing to put in your ten years/10,000 hours. Program. The best kind of learning is learning by doing. To put it more technically, "the ...


7

So we did an analysis of the two (+ HTML 5) for our purposes and found that JavaFX narrowly won out due to our familiarity with Java and Java based tooling and support stacks. Our methodology was to list 20 criteria and rank each technology out of 10 for each. For example, i18n, ease of hiring, x-platform support, mobile support, strength of commnuity, ...


7

As you already discovered, putting all unit tests into one huge file is not a good practice (same as putting all classes into one file is bad as well, although it compiles a bit faster). You should create a subdirectory unittests where all unit tests go. It should be one file per class. This way you do not clutter your code with unit tests. If you can, ...


7

My quick two bits on this: 10 (sorry terrible joke). To expand slightly, here goes: 1- A static library can depend on another static library, nothing or even a dynamic library: in the first two instances all the code for the new static library would be incorporated in the new SLL (Static Link Library), however, the 3rd option, depending on evironment could ...


6

Usually, this can be solved by writing a GUI front-end that builds a command line. At that point you simply call the old CLI "main()" function with the arguments in the appropriate order. What you need to do then, depends on the output. You might do well by wrapping all printf()'s in a generic output variadic function, that in the CLI version will just pass ...


6

Rewriting a project of this size is doomed to fail due to the reasons in Michael Kohne's post. Refactoring a buggy codebase is difficult because you'll never know if bugs are due to your refactoring or due to the original code. I would take the approach of doing nothing but bug fixes for a significant period of time. As part of these bug fixes, you can ...


6

When you declare something you just promise that during linking it will be available and uniquely identified. Static libs are nothing more than containers for definitions in a format which is outside the standard. So, this has the following implications: 1 ) I don't quite get what you're asking here, but one static library can very much depend on another ...


6

In modern C++ you typically want to use the Resource Acquisition Is Initialization (RAII) idiom. The idea is that any resource that you allocate should be wrapped into a class, and it should be deleted/closed/cleaned up by the class's destructor. A resource is anything that you need to de-allocate, close, or otherwise clean up when you are done with it. Most ...


6

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: The whole geometry would have to be rendered using single shader. Having separate shaders (for opaque copy, transparent copy, gradient, ...) is more useful. The ...


6

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 as argument and method will decide if it wants to use open/close if they are set.


6

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 you'll have to follow the terms of the (L)GPL or pony up for a commercial QT license. As for static vs dynamic linking, you can static link with an (L)GPL ...


6

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 and it's immune to C++'s most vexing parse. -- Scott Meyers, in Effective Modern C++, Item 7 You have to be aware that there might however be a subtlety ...


5

I agree with most of high praise of Qt, but the question was What's the best GUI framework to use that allows/requires the most use of generic C++ and the STL? In this respect Qt is a little schizophrenic: it duplicates STL containers and algorithms with it's own twists. It also provides containers, which are different than STL. Interoperability between Qt ...


5

For learning C++, Qt has some good things and some bad things. The good: It provides the building blocks for everything you might want to do with C++, from network programming and threads to OpenGL and displaying web content. It has a few tricks up it sleeves to make things a little easier. For example, it uses the parent hierarchy to handle object ...


Only top voted, non community-wiki answers of a minimum length are eligible