Subclassing QTextEdit

  • I am trying to subclass QTextEdit to edit input so I can create symbolic math formula, but cannot get past the vtable issue.


    #include <QObject>
    #include <QWidget>
    #include <QTextEdit>

    class FormulaEditor : public QTextEdit
    explicit FormulaEditor(QWidget *parent = 0);
    // ~FormulaEditor();

    FormulaEditor::FormulaEditor(QWidget *parent) : QTextEdit(parent)


    The commented out code was an attempt to get past the vtable problem. I have seen posts were other have done what I am attempting and my code is no defferent. Any suggestions? (I have promoted a Qt Creator QTextEdit to FormulaEditor.)

  • @ofmrew

    Seems , you have forgotten
    # include"forumualrEdit.h" in cpp

  • make sure the pro file contains something like HEADERS += formulaeditor.h and re-run qmake

  • Qt Champions 2017

    @ofmrew said in Subclassing QTextEdit:


    You are not showing the actual error.

    Try to Clean all, run qmake and the rebuild all.

  • Qt Champions 2017

    Thrash the build directory and rebuild it. It will solve the issue.

  • @Ni.Sumi

    It is there I just did not show it.

  • @dheerendra

    I did not understand "trash the build directory" but I did some of the items under the Build menu and now it works. Apparently I did trash the build directory, but now I want to know how I did it? Where is the build directory? And how do I trash it?


  • @ofmrew

    Okay. Did you do this as @VRonin @mrjj and @dheerendra said ?

    Clean , and then Run qmake and then build ?

  • Qt Champions 2017

    The build folder means the folder where it generates all the .o files and other stuff.
    it will be in the same folder LEVEL as the project.
    So goto the project folder, then one up and u should see build-xxxx-yyyy
    And trash just means delete it.

  • @ofmrew

    In Qt , whenever you add some new file (change in the file) to your application, you need to run the qmake. Otherwise it will use the old files on your machine. When you run qmake, it will include the new files. qmake generates the platform dependent make files.

    Built directory depends on you, where you allowed to build. Usually , you can find the path of the folder here


  • @mrjj and Ni.Sumi

    I did Clean , and then Run qmake and then build as you suggested.

    I normally just use Run (Green Triangle), which has always done the compile and execute with no problem; however, that now seems to be inadequate. If I always do a build, then will problems like this not occur?

  • Qt Champions 2017

    Well in normal development the RUN is enough.
    But if u add to the pro file and rerun qmake, and it still makes errors then
    removing the build folder will force it to recreate all.
    It caches some stuff so sometimes its the best solution.

  • @mrjj

    Thanks. I will remember this as I wasted hours chasing a phantom error.

  • Qt Champions 2017

    Yep most of us have been there done that :)
    So to make the "rules" clear.
    if you add files to .PRO
    if you add the Q_OBJECT macro
    If you rename slots and its keeps acting up

    Then delete the build folder to be sure its an actual error and not just due to it using a
    cached version.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.