0

I want to subclass the "QStackedWidget" class to add some public slots but when I add its header and source to my Qt project, my project can't be built completely and after showing many compiling errors and warnings, Qt gets crashed.

This is my QStackedWidget-inherited class header below:

#ifndef QSTACKEDWIDGETV2_H
#define QSTACKEDWIDGETV2_H

#include <QWidget>
#include <QStackedWidget>

class QStackedWidgetV2 : public QStackedWidget
{
public slots:
  void GoToNextPage();
  void GoToBackPage();
  void JumpToPage(qint32 index);
public:
  QStackedWidgetV2();
  ~QStackedWidgetV2();
}

#endif // QStackedWidgetV2

And these are some of the given compiling and warning errors. However, Qt showed me a lot of other errors but they were similar: s

  • 5
    Looks like maybe some of your Qt header files got corrupted somehow? You might have to open qstackedwidgetv2.h in a text editor, see what file is #include'd at line 5, and then check out that file to see if there are stray characters in it. – Jeremy Friesner Jun 29 '21 at 17:01
  • 2
    offtopic: `Q` is a prefix for a library (here Qt) - this was common technique used before namespaces were introduced. So basically you should never use this prefix - doesn't meter what you are inheriting. – Marek R Jun 29 '21 at 17:01
  • The stray errors indicate you have some unexpected characters in the Qt header. Did you accidently edit the `QStackedWidget` header file while debugging or something? – drescherjm Jun 29 '21 at 17:01
  • 1
    Instead screenshot please copy text from "compiler/build output" window - there should be errors in text format. – Marek R Jun 29 '21 at 17:02
  • 1
    offtopic2: `Q_OBJECT` macro is missing – Marek R Jun 29 '21 at 17:06
  • 2
    On error: your source file most probably was saved with invalid encoding. `stray '\xxx' in program` means that compiler encounter character invalid for current encoding. Probably is some step you were using none English characters or you did something strange. – Marek R Jun 29 '21 at 17:10
  • @MarekR, adding 'Q_OBJECT' to the class declaration didn't solve the problem, either. I did it, but I'm still getting the same errors and warnings. – Amir Mohsen Jun 29 '21 at 17:54
  • The Q_OBJECT bug is independent of the corrupted / modified Qt header problem. – drescherjm Jun 29 '21 at 17:55
  • @Jeremy Friesner, you're right. I changed my platform and ran Qt again and the problem is solved. – Amir Mohsen Jun 29 '21 at 18:14

0 Answers0