简体   繁体   中英

Broken indentation for Qt-specific constructions in Visual Studio

Automatic indentation in VS editor obviously does not know about Qt. And declarations of signals and slots are auto-formatted like this:

   class MyClass : public QObject
   {
   Q_OBJECT
   public:
      MyClass();

signals: // <-- Broken indentation
      void someSignal();

      public slots: // <-- Also broken
         void someSlot();
   };

I want "signals:" and "slots:" automatically formatted just like access specifiers. What are the options? (I'm using VS2010)

In short answer seems to be NO. Maybe not what you are looking for but maybe you can live with this:

class MyClass : public QObject
   {
   Q_OBJECT
   public:
      MyClass();

   private:
      Q_SIGNAL void someSignal();

   public:
      Q_SLOT void someSlot();
   };

(It's ugly but it seems you can't have your cake and eat it too ;)

Just something I'm wondering about: Is it worth the effort to build a plugin for automatic formatting? Do we really use CTRL-A CTRL-F so much? If so, then yes it could be a pain. But normally if you are working on header files declaring a new method (signal or slot) should not mess up the previous corrected indentation. Perhaps you have some reasons that justifies this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM