Class inheritace issue - syntax error

Heads up! You've already completed this tutorial.

anneranch24425664 | 2020-07-29 10:43:38 UTC | #1

I am hacking existing python code - my first project. I am following a simple tutorial to add / make tab dialog.

Even after adding the "from ... import" ( not covered in tutorial ) to the module I keep getting "invalid syntax " .

I am using Linux / Eclipse /python3.7 and my hacked code, which uses PyQt5 generally works. .

python
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QPushButton, QLabel,QDialog
import sys

class TabDialog : public  QDialog
{
    Q_OBJECT

public:
    explicit TabDialog(const QString &fileName, QWidget *parent = nullptr);

private:
    QTabWidget *tabWidget;
    QDialogButtonBox *buttonBox;
};

  File "/media/z/DEV_COPY_LABEL/ECLIPSE_FOLDER/Eclispe_WORK_724/workspace/work_python_727/nanovna-saver_728/NanoVNASaver/Widgets/CCC_Widgets/CCC_TabDialogWidget.py", line 47
    class TabDialog : public  QDialog
                                    ^
SyntaxError: invalid syntax

The caret '^' is actually pointing / located under "public"


martin | 2020-07-29 10:46:36 UTC | #2

Hey @anneranch24425664 welcome to the forum.

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 15,000 copies sold!

More info Get the book

The code you've posted contains C++ code which is invalid Python. For example the line it is complaining about

cpp
class TabDialog : public  QDialog

...would be...

PyQt/PySide 1:1 Coaching with Martin Fitzpatrick — Save yourself time and frustration. Get one on one help with your Python GUI projects. Working together with you I'll identify issues and suggest fixes, from bugs and usability to architecture and maintainability.

Book Now 60 mins ($195)

python
class TabDialog(QDialog):

in Python. Everything after that (the public and private sections) are not required in Python so can be deleted completely.

Can you post a link to where you got the code from? It should be possible to convert it to Python.

The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

Class inheritace issue - syntax error was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.