Broken indentation for Qt-specific constructions in Visual Studio

社会主义新天地 提交于 2019-12-10 03:10:36

问题


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)


回答1:


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?



来源:https://stackoverflow.com/questions/5496811/broken-indentation-for-qt-specific-constructions-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!