Skip to content

C++ Gurus

The forum for all discussions in C++ land.
1.3k Topics 8.6k Posts
  • 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
    607 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
    449 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
    853 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
    618 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
    426 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
    697 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
    388 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
    836 Views
    JoeCFDJ
    Works. Thank Christian again.
  • reinterpret_cast for received tcp packets

    Solved
    26
    0 Votes
    26 Posts
    5k 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
    7k 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
    331 Views
    No one has replied
  • QGiS in WIndows

    Unsolved
    1
    0 Votes
    1 Posts
    272 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.
  • Unable to create C++ google test for the C++ class

    Unsolved
    6
    0 Votes
    6 Posts
    1k Views
    Christian EhrlicherC
    See https://doc.qt.io/qt-6/debug.html : set QT_FATAL_WARNING, run your app in the debugger and see where you create a QWidget before a QApplication.
  • To singleton or not to singleton, that is the question....

    Solved
    23
    0 Votes
    23 Posts
    5k Views
    S
    @JoeCFD said in To singleton or not to singleton, that is the question....: Calling baz() with using "using Foo;" can cause confusing while two namespaces are present at the same place. In the concrete example you have given, it would not compile because the compiler cannot resolve the overload (i.e. Foo1::baz or Foo2::baz). You'd still need to use a fully qualified name. It only gets confusing when you have Foo1::baz(int) and Foo2::baz(double). You might write baz(1); when you actually want to call Foo2::baz. The software might even do the right thing for years. Someone might just introduce Foo1::baz years down the line and suddenly the behavior changes.
  • Template class as parameter question

    Solved
    6
    0 Votes
    6 Posts
    1k Views
    S
    @JonB said in Template class as parameter question: What happens when another container has a different definition of count() which does not return an int (or number)? Maybe your syntax is not quite correct and it would have to be requires(T t) { int t.count(); }? I guess this would be some additional requirement using std::is_same_v and decltype(t.count()). I'm still on C++17, so I haven't used concepts myself. @JonB said in Template class as parameter question: Hmph! But that's is just what e.g. QList is, and loads of other containers. A container class is an obvious example where a general purpose implementation makes sense. But, you usually don't implement your own containers. Furthermore, most of the time I would have at least int and double in mind for containers. So, making them general purpose from the get go is a given. But, I don't have to make all my algorithms general purpose such that they might be reusable decades down the line if ever. If there is a current need for general purpose code, make it general purpose. Otherwise it just make maintenance more complicated while being unnecessary. I guess it might also introduce additional bugs because you try to be extra clever.