Skip to content

C++ Gurus

The forum for all discussions in C++ land.
1.3k Topics 8.6k Posts
  • Model View Design challenge with larger dataset

    Unsolved
    21
    0 Votes
    21 Posts
    433 Views
    S
    @JonB correct
  • I hear crickets chirping

    Unsolved
    25
    0 Votes
    25 Posts
    999 Views
    S
    @Kent-Dorfman said in I hear crickets chirping: Doesn't anyone have any esoteric C++ incantations to discuss. It's too quiet in here. Change of topic: I recently found some esoteric C++ incantations: a constexpr counter based on template instantiation: https://b.atch.se/posts/constexpr-counter/ . However, it seems that this behavior is about to be deprecated (you cannot rely on the order templates are instantiated). At the same time, something quite similar has occured in one of the reflection examples (https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2996r12.html Chapter 3.17 "Compile-Time Ticket Counter"). This reflection proposal has been accepted, so we might be able to safely do a constexpr counter through reflection starting with C++26.
  • Using QList [] operator in const methods

    Solved
    10
    0 Votes
    10 Posts
    274 Views
    Kent-DorfmanK
    @SimonSchroeder said in Using QList [] operator in const methods: Even if operator[](int) const returns a copy you have the exact same possible race condition in a multithreading environment. The only advantage is that it is fewer lines of code where this might occur. Multithreading seems an irrelevant point though because the competent programmer understands that accessing a shared resource needs a mutex, so if safe programming processes are observed then there is no race condition. re const vs non-const: totally agree and get it. It's the way things are...however, I do sometimes wish nothing was ever const and everything was mutable. :^)
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • Problem with calculating CRC

    Moved Solved
    4
    0 Votes
    4 Posts
    684 Views
    SGaistS
    Hi, I think you went the too complicated road: quint16 calculateCrc16Arc(const QByteArray &data) { quint16 crc = 0x0000; const quint16 poly = 0xA001; for (char byte : data) { crc ^= (static_cast<quint8>(byte)); for (int i = 0; i < 8; i++) { crc = (crc & 0x0001) > 0 ? (crc >> 1) ^ poly : (crc >> 1); } } return crc; }
  • QT6 vs. utf-8 in VS2022

    Solved
    2
    0 Votes
    2 Posts
    467 Views
    W
    Solved by myself. I found "-utf-8" in two .conf files..
  • Qt6.x QFlags / error C2593: 'operator ==' is ambiguous

    Solved
    7
    0 Votes
    7 Posts
    881 Views
    W
    Solved! I think this error was also related to the compiler option "/Zc:hiddenFriend-".
  • 0 Votes
    19 Posts
    4k Views
    W
    Found it! This error was caused by the compiler option "/Zc:hiddenFriend-" !
  • Can Anybody explain what is basic syntax of given specialize template?

    Solved
    4
    0 Votes
    4 Posts
    657 Views
    S
    In general you define a simple template class like this: template<typename T> class A { }; This can then be used with A<int> myA; Sometimes you want to have a different implementation for a specific type which we call a template specialization: template<> class A<int> { }; Just as with function overloading where the compiler picks the function with the best fit for the parameter types, the compiler will pick the most specific specialization. Sometimes you don't want a specific type but some specific sort of type, e.g. a pointer: template<typename T> class A<T*> { }; Now, if you write A<int*> pInt; or A<double*> pDouble; it will match the specialization for pointers. In the same way class Logger3<R(Args...)> will match any function as template argument. One of the "modern C++" features is Args... which means any number of types (0 or more). (The ... introduces a list of types.) So, R(Args...) can match void() or void(int) or int(double,int) etc. Because we are just interested in the function signature this looks like a function declaration, but without any function name between the return type and the argument list.
  • Shared Library __declspec(dllexport) __declspec(dllimport) question

    Solved
    2
    0 Votes
    2 Posts
    456 Views
    Christian EhrlicherC
    When you want to include some headers of a library you also must pass the include path to the compiler. If you use cmake, use target_include_directories() and add the desired include paths there. Later when you use this library (aka you link them with target_link_libraries()), cmake will automatically add the paths specified.
  • 0 Votes
    13 Posts
    3k Views
    Christian EhrlicherC
    clazy is also using libclang
  • Ferramenta Zoom C++

    Unsolved
    5
    0 Votes
    5 Posts
    760 Views
    SGaistS
    Hi and welcome to devnet, What are you using currently ? QtQuick ? The graphics view framework ?
  • error with qtcharts

    Unsolved
    2
    0 Votes
    2 Posts
    440 Views
    Christian EhrlicherC
    See https://doc.qt.io/qt-6/qtcharts-changes-qt6.html
  • Need help from C/C++ experts with VS on Windows

    Solved
    4
    0 Votes
    4 Posts
    872 Views
    JoeCFDJ
    Works. Thank Christian again.
  • reinterpret_cast for received tcp packets

    Solved
    26
    0 Votes
    26 Posts
    6k Views
    S
    @Redman said in reinterpret_cast for received tcp packets: 01:00:00:00:01:00:01:00:00:00:01:00:00:00:00:00:00:00:01:00:00:00 This is what you'd expect for a packed struct (as you have figures out). It worked before because both sides were using C++ and so both sides were not using packed structs (so much about the "well defined protocol"). In order to not have that problem @J-Hilk is right to write a constructor expecting a QByteArray. For sending you should also pack the members into a QByteArray yourself. This also makes you immune to the order of the members (which is only guaranteed by a very, very recent C++ standard). It is also common practice to order members from biggest to smallest, so you can adhere to alignment rules and still get the most compact representation. This would also solve your problem (on the C++ side; I don't know Python) that you don't have to explicitly pack the struct.
  • Iterator as a member: Tree/Graph-like structure

    Unsolved qlist iterator sequence graph
    35
    0 Votes
    35 Posts
    8k Views
    Pl45m4P
    @GrecKo said in Iterator as a member: Tree/Graph-like structure: pick the container with the friendliest API depending on how you plan to access it. Still what @Christian-Ehrlicher and @JonB suggested doesn't sound too bad :) Will definitely try it. Similar question: Why is QButtonGroup using a QHash-map for its member buttons? :)) I doubt that there ever will be thousands of button widgets in one group :)
  • The Question of a Lifetime

    Unsolved
    5
    0 Votes
    5 Posts
    1k Views
    Kent-DorfmanK
    @SimonSchroeder Your description above is in substance, correct. I had to check it to make sure myself. ;^) By assigning the string literal to an array (const or not) it is considered "auto class". When you create a pointer to the string literal the pointer will "typically" point to a RO-data segment containing the literal.
  • 0 Votes
    1 Posts
    339 Views
    No one has replied
  • QGiS in WIndows

    Unsolved
    1
    0 Votes
    1 Posts
    304 Views
    No one has replied
  • Problem using overridden methods

    24
    0 Votes
    24 Posts
    16k Views
    Pl45m4P
    @osirisgothra said in Problem using overridden methods: I do really like being able to do this: which opens a wonderful window that You could write a QtCreator extension/plugin and try to find out how to get your hand on the data you need. displays EVERY child class of that object with a checkbox by each function. You can just check off each signature you want to override Probably via the Code Model / Symbols. If you wanna try it, start a new topic. People who have more experience with such things than I do may be able to help you then.