Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Tossing around the idea for this QtCreator "Quick Fix"....

Tossing around the idea for this QtCreator "Quick Fix"....

Scheduled Pinned Locked Moved Unsolved Brainstorm
2 Posts 2 Posters 48 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • osirisgothraO Offline
    osirisgothraO Offline
    osirisgothra
    wrote last edited by
    #1

    I have seen, on occasion, the detach warning when people write:

        // assuming that:
        QList<QSomeType> someList; // or whatever
    // This... or an iterator loop with similar issues...
        for (const QSomeType &someVar : someList)
            someVar.doneQuestionably(); // or somevar-> depending on decorators
    

    I noticed that 99% of these I stumble upon are easily fixed:

        // ..that could be simply solved by:
        foreach (const QSomeType &somevar, somelist)
            someVar.doneRight();
    

    We all know this, yes of course we do. But it still stands that some do not, which is why there is a nice warning from CLazy about it.

    What I'd like to know is, what do you think about this solution being added to quick fixes? I mainly am interested in it because we could probably reduce the total global presence of these kinds of loops for reasons(see list below) and maybe because they simply didn't realize (or wanted to take the time to find out) that they could.

    List of reasons (common to least):

    • turned off CLazy or does/can not use it
    • has become "numb" to this warning and their brain physically sees "nothing serious, code on..."
    • feels that since the object is a Qt type (somehow) it can't possibly cause any issues or do anything bad
    • wrote their code so fast and never came back that Clazy didn't have a chance to even complain :3
    • convinced that they want "real" loops and need range loops (but there ain't no way they're ever going to love them)
    • the idea that using foreach is not as clean as using ranged loops because it is not using a native expression or keywords
    • some people just don't like macros at all, but are kidding themselves if they actually think can avoid them while using Qt

    So what do ya think? Quick fix feasible? My one concern is that not every situation (esp for non-qt stuff) is going to be fixable, but for the most part, if you are using C++ in QtCreator, are a beginner/novice, you are very likely using Qt objects rather than writing plain C++ code.

    This only eats at me each day because I've fixed so many of these in foreign code I've lost count. And I'm not talking old, legacy code, I am talking code that was recently written with modern Qt versions just shy of the bleeding edge. It boggles my mind, but then maybe I'm just having a case of POCPD (Programmer's Obsessive-Compulsive Programming Disorder which is another story for another time).

    I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

    1 Reply Last reply
    0
    • J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote last edited by J.Hilk
      #2

      You don't have deprecation warnings on, or you would not suggest foreach :P

      Don't use it, I'm surprised its still in the library

      I would suggest simply writing the c++ way with std::as_const

      Or if you insist on "simpler" macros:

      #include <utility>   // std::as_const
      
      #define FOREACH_CONST(var, container) \
          for (const auto& var : std::as_const(container))
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved