Skip to content

C++ Gurus

The forum for all discussions in C++ land.
1.3k Topics 8.3k Posts
  • 0 Votes
    10 Posts
    236 Views
    jsulmJ

    @Qtpp said in How to find symbols in extern code files or projects and get their "type" (code analysis library)?:

    is it somehow possible to reach out to one of the QtCreator maintainers/devs

    https://lists.qt-project.org/listinfo/qt-creator

  • Is it possible to prevent `delete` on a `const *`?

    Solved
    17
    0 Votes
    17 Posts
    282 Views
    Chris KawaC

    @SimonSchroeder said:

    But I'm not sure if this distinction is possible

    It's not. The delete operator can't be cv qualified.

    Here's a fun quirk:

    struct Foo { void itIsFine() const { delete this; } ~Foo() { bar = 42; } int bar = 0; }; const Foo* foo = new Foo(); foo->itIsFine();

    so not only can you delete an object through a pointer to const, but a const function can mutate the object without mutable or const_cast by deleting the object it is being called on;)

  • __attribute__((???)) ignored

    Solved
    5
    0 Votes
    5 Posts
    108 Views
    Kent-DorfmanK

    @jeremy_k

    that is weird. some examples place the directive after the declaration and others before like it shouldn't matter...but you are right. It did make a different. Placing it before the declation cause the warning to be igrnored.

    looks like gcc documention is wrong...go figure. LOL

    wrong in TWO PLACES...First, they say "unused" is a valid attribute, and second, internal examples sometimes place the attribute after the decl.

    Hmmm.

  • can't compare lists of my struct

    Solved
    8
    0 Votes
    8 Posts
    163 Views
    Pl45m4P

    @mzimmers said in can't compare lists of my struct:

    I removed the QObject derivation, and now it seems to work.

    If you don't plan to ever use meta-object related stuff, then you really don't need a QObject derived class or the Q_OBJECT macro (for metacalls / qt signals).

  • Same question

    Unsolved
    2
    0 Votes
    2 Posts
    54 Views
    Axel SpoerlA

    Which Qt Version and C++ standard are you using?

  • 0 Votes
    14 Posts
    1k Views
    S

    I have a same question,but I can't change Qt Version or c++ standard. do you have other suggestions?
    Thank you in advance for your help

  • 0 Votes
    8 Posts
    197 Views
    JonBJ

    @Bharath-kumar
    As @Christian-Ehrlicher has said. I don't understand: in your code you know how to produce a certain number of digits via QString formattedString = QString::number(doubleValue, 'e' , 4);, so why do you have QString dataString = data.toString(); earlier and expect that to produce a limited number of digits?

  • matherror issue

    Unsolved
    17
    0 Votes
    17 Posts
    249 Views
    Q

    @JonB said in matherror issue:

    If the int _matherr (struct _exception *pexcept) appears in merr.c you need to trace from there to find out where it (_exception) is defined. Maybe it's a MinGW-only definition/file, I don't know.

    If I compile in Clang

    int err_ind = 0; int _matherr (struct _exception *pexcept) { err_ind = 1; }

    Compilation OK, but math exception doesn't work

  • Integrating C++ Software into Qt Desktop Application

    Unsolved
    3
    0 Votes
    3 Posts
    124 Views
    S

    If you want an integrated application (not the variant with QProcess that @SGaist suggested), the first step would be to separate your command line application: parse the command line parameters into variables and the actual functionality should then be refactored to a separate function, that takes these variables as function arguments. This ensures, that the same function can be called from your GUI application. Inside the GUI application you would then have input widgets for each variable and a button labeled "Run" (or similar). When "Run" is clicked, you collect all the different inputs and call your refactored function. If this takes longer to run, you should put it into a separate thread (and then the other solution "use a QProcess" is not too different to implement, though for the perfect solution threads should be used, but QProcess will be easier). Maybe for threading a simple QtConcurrent::run() will suffice.

    You will have some trouble if there is important console output (writing to stdout/stderr) of your existing application. How do you want to interact/signal errors? For a good solution this would require deeper changes into your existing application. With the QProcess approach the only thing you can do is to show the output to the user. Otherwise, you could use callback function for output. In the case of your command line application this can still write to the console by default, and for your GUI application you register a callback that shows a QMessageBox. Maybe the callback can even return a value (e.g. from the message box) to continue or abort.

  • C++ named parameters?

    Solved
    4
    0 Votes
    4 Posts
    114 Views
    Pl45m4P

    @JonB

    I think it's some kind of hint for the reader to understand the source code better without browsing the whole class.
    Like:

    in some class.h where someFunction(int a, int b, float c) is declared

    void someFunction(int a, int b, float c);

    and (if I'm correct) everywhere the function is used, on every call, the code browser adds the names from the header, so you know right away what this

    // some code // ... someFunction(42, 42, 13.37); // ...

    means.

    With the hint it looks like:
    ( imagine meaningful names there :D )

    someFunction( [ a ]: 42, [ b ]: 42, [ c ]: 13.37);

    Therefore I don't think it's C++ :)
    Btw: I also like woboq to check Qt source code :)

  • how to declare global (static?) function inside class?

    Solved
    4
    0 Votes
    4 Posts
    122 Views
    JoeCFDJ

    @mzimmers inline might be more convenient. No need to define it in cpp file.

    inline static bool m_use24hourTime{ false };
  • How to debug / verify running Qt code ?

    Unsolved
    2
    0 Votes
    2 Posts
    91 Views
    No one has replied
  • LDAP - Linux

    Unsolved
    2
    0 Votes
    2 Posts
    57 Views
    jsulmJ

    I think you will have to use something like https://www.openldap.org/software/man.cgi?query=ldap

  • 0 Votes
    4 Posts
    169 Views
    Pl45m4P

    @J-Hilk said in Repost Parent / children / methods ? which way up ?:

    (Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship)

    Oh boy... Had to read this for my studies :D
    Pretty helpful and well structured "guide" on how (not) to write code.

  • QObject iterator for QAction

    Unsolved
    7
    0 Votes
    7 Posts
    168 Views
    A

    @J-Hilk arrrrrrrrrrrrr

  • QObject or QAction?

    Unsolved
    2
    0 Votes
    2 Posts
    92 Views
    Axel SpoerlA
    QAction *action = qobject_cast<QAction *>(pItemObject);

    Has been explained to you before.

  • 0 Votes
    6 Posts
    150 Views
    Christian EhrlicherC

    I'm sorry that you have to read documentation if you want to learn something. Especially something such basic c++ stuff.

  • How to iterate "parent" objects?

    Unsolved
    4
    0 Votes
    4 Posts
    151 Views
    Christian EhrlicherC

    To access the grandparent use parent()->parent()

  • How to execute QList "action" ?

    Unsolved
    3
    0 Votes
    3 Posts
    121 Views
    Axel SpoerlA

    Dear @AnneRanch,
    you are not supposed to simply delete posts, if they have become irrelevant and/or solved.
    The rules in this forum are to mark them solved, when they are.
    This is because they are likely to be a reference for others with similar issues.

  • How to unit test with functions loaded from win32 api?

    Unsolved
    5
    0 Votes
    5 Posts
    296 Views
    SGaistS

    @Paul-Colby is hinting at something good. If you want to be able to cleanly test things, you should consider making a library with all your widgets and business logic and your application will be mainly a main.cpp file using that library. This will allow you to build a test suite for your library in a simpler fashion.