Skip to content

C++ Gurus

The forum for all discussions in C++ land.
1.3k Topics 8.3k Posts
QtWS25 Call for Papers
  • how to stop copy of a large file

    Unsolved
    7
    0 Votes
    7 Posts
    173 Views
    Kent-DorfmanK

    FWIW, since you are using the STL streams classes, note that you have buffer size control in the STL classes. One could weakly argue that you should use the Qt file IO methods instead of STL streams, since mixing frameworks is often the cause of problems in programming.

  • 2 Votes
    17 Posts
    255 Views
    JonBJ

    @Pl45m4
    I am now good on the algorithm. The one I am using (via @J-Hilk/ChatGPT) gives me a satisfactory answer I can work with and place my objects.

  • Some C++ questions about using <random>

    Unsolved
    8
    0 Votes
    8 Posts
    135 Views
    JonBJ

    @SimonSchroeder
    Sorry, but I don't think any part of my questions relate to random numbers or generators or distribution/uniformity performance. They are questions about C++ (especially the as-yet-unanswered question #3). With regard to the static-ness/number of times to call the initial "seeding" when comes with std::random_device rd; std::mt19937 gen(rd()); I only wish to reseed once and then accept the random number which comes from that, as is standard practice with random number generators (e.g. for old-style rand() we used to call srand() just once).

  • How to add "new line " to QString ?

    Unsolved
    5
    0 Votes
    5 Posts
    370 Views
    K

    QString myString = "First line\nSecond line"

  • 0 Votes
    10 Posts
    302 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
    381 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
    135 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
    184 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
    74 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
    257 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
    311 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
    168 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
    144 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
    154 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
    111 Views
    No one has replied
  • LDAP - Linux

    Unsolved
    2
    0 Votes
    2 Posts
    86 Views
    jsulmJ

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

  • 0 Votes
    4 Posts
    191 Views
    Pl45m4P

    @J-Hilk said in Repost Parent &#x2F; children &#x2F; 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
    200 Views
    A

    @J-Hilk arrrrrrrrrrrrr

  • QObject or QAction?

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

    Has been explained to you before.