Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Error in using MultiPageWidget from QtDesigner



  • Hello , I Want to use MultiPageWidget in QtDesigner
    this is the url of the image of Widget : "https://ibb.co/cDzBZ6K"

    so i searched how to use it and reached to this document
    https://doc-snapshots.qt.io/4.8/designer-containerextension.html#multipagewidget-class-definition
    and made everything as mentioned
    this is .pro file

    #-------------------------------------------------
    #
    # Project created by QtCreator 2018-12-24T22:54:39
    #
    #-------------------------------------------------
    
    QT  += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets designer
    
    TARGET = Hospital-ClinicSoftware
    TEMPLATE += app lib
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    CONFIG += c++11 designer plugin
    
    SOURCES += \
            main.cpp \
            mainwindow.cpp \
        mainprocess.cpp \
        showingdata.cpp \
        delgate.cpp \
        profile3.cpp \
        profile.cpp \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidget.cpp \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidgetplugin.cpp \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidgetcontainerextension.cpp \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidgetextensionfactory.cpp
    
    HEADERS += \
            mainwindow.h \
        mainprocess.h \
        showingdata.h \
        delgate.h \
        profile3.h \
        profile.h \
     /usr/lib64/qt5/examples/designer/containerextension/multipagewidget.h \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidgetplugin.h \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidgetcontainerextension.h \
                /usr/lib64/qt5/examples/designer/containerextension/multipagewidgetextensionfactory.h
    
    
    
    FORMS += \
         mainwindow.ui \
        mainprocess.ui \
        showingdata.ui \
        profile3.ui \
        profile.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path += /opt/$${TARGET}/bin $$[QT_INSTALL_PLUGINS]/designer
    !isEmpty(target.path): INSTALLS += target
    

    this is an image of multipagewidget.cpp
    and error i get while compiling
    the url of the image : "https://ibb.co/cDzBZ6K"

    this is profile.h and libraries i've included and this also the profile.ui which i want to use this widget in

    #ifndef PROFILE_H
    #define PROFILE_H
    
    #include <QWidget>
    #include <QApplication>
    #include <QtSql>
    #include <QtDebug>
    #include <QSqlDatabase>
    #include <QSqlQueryModel>
    #include <QDebug>
    #include <QSqlQuery>
    #include <QMessageBox>
    #include <QSqlDriver>
    #include <QVector>
    #include <QCheckBox>
    #include <QStackedWidget>
    #include <QtDesigner>
    #include <QDesignerContainerExtension>
    


  • @MostafaEzzat
    So the error message states it cannot find multipagewidget.h. Have you copied that to somewhere it can be found for your project you want to use it in, or where are you expecting it to find it?



  • @JonB
    Actually it gives an errors in multipagewidget.h itself which downloaded with Qt5 Files
    and the errors are :
    1-/usr/lib64/qt5/examples/designer/containerextension/multipagewidget.cpp:62: error: ‘QStringLiteral’ was not declared in this scope
    comboBox->setObjectName(QStringLiteral("__qt__passive_comboBox"));
    ^~~~~~~~~~~~~~
    2-/usr/lib64/qt5/examples/designer/containerextension/multipagewidget.cpp:64: error: ‘QOverload’ was not declared in this scope
    connect(comboBox, QOverload<int>::of(&QComboBox::activated),
    ^~~~~~~~~
    3-/usr/lib64/qt5/examples/designer/containerextension/multipagewidget.cpp:64: error: expected primary-expression before ‘int’
    connect(comboBox, QOverload<int>::of(&QComboBox::activated),
    ^~~
    4-/usr/lib64/qt5/examples/designer/containerextension/multipagewidget.cpp:111: error: ‘windowTitleChanged’ is not a member of ‘QWidget’
    connect(page, &QWidget::windowTitleChanged,
    ^~~~~~~~~~~~~~~~~~
    and this the image of multipagewidget.cpp 's errors
    url : https://ibb.co/cDzBZ6K

    this is multiwidget.h file

    /****************************************************************************
    **
    ** Copyright (C) 2016 The Qt Company Ltd.
    ** Contact: https://www.qt.io/licensing/
    **
    ** This file is part of the examples of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:BSD$
    ** Commercial License Usage
    ** Licensees holding valid commercial Qt licenses may use this file in
    ** accordance with the commercial license agreement provided with the
    ** Software or, alternatively, in accordance with the terms contained in
    ** a written agreement between you and The Qt Company. For licensing terms
    ** and conditions see https://www.qt.io/terms-conditions. For further
    ** information use the contact form at https://www.qt.io/contact-us.
    **
    ** BSD License Usage
    ** Alternatively, you may use this file under the terms of the BSD license
    ** as follows:
    **
    ** "Redistribution and use in source and binary forms, with or without
    ** modification, are permitted provided that the following conditions are
    ** met:
    **   * Redistributions of source code must retain the above copyright
    **     notice, this list of conditions and the following disclaimer.
    **   * Redistributions in binary form must reproduce the above copyright
    **     notice, this list of conditions and the following disclaimer in
    **     the documentation and/or other materials provided with the
    **     distribution.
    **   * Neither the name of The Qt Company Ltd nor the names of its
    **     contributors may be used to endorse or promote products derived
    **     from this software without specific prior written permission.
    **
    **
    ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/
    
    #ifndef MULTIPAGEWIDGET_H
    #define MULTIPAGEWIDGET_H
    
    #include <QWidget>
    
    QT_BEGIN_NAMESPACE
    class QComboBox;
    class QStackedWidget;
    QT_END_NAMESPACE
    
    //! [0]
    class MultiPageWidget : public QWidget
    {
        Q_OBJECT
        Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex)
        Q_PROPERTY(QString pageTitle READ pageTitle WRITE setPageTitle STORED false)
    
    public:
        explicit MultiPageWidget(QWidget *parent = nullptr);
    
        QSize sizeHint() const override;
    
        int count() const;
        int currentIndex() const;
        QWidget *widget(int index);
        QString pageTitle() const;
    
    public slots:
        void addPage(QWidget *page);
        void insertPage(int index, QWidget *page);
        void removePage(int index);
        void setPageTitle(QString const &newTitle);
        void setCurrentIndex(int index);
    
    private slots:
        void pageWindowTitleChanged();
    
    signals:
        void currentIndexChanged(int index);
        void pageTitleChanged(const QString &title);
    
    private:
        QStackedWidget *stackWidget;
        QComboBox *comboBox;
    };
    //! [0]
    
    #endif
    
    


  • @MostafaEzzat
    The image link you show, just like before, just shows "cannot find multipagewidget.h" from your source file. If it can't find it then it can't give errors from inside it. I'll leave it someone else, you need to sort how you are building.



  • @JonB
    OOPS , Sorry i missed

    this is the image of error and the errors it self in the previous reply
    url : "https://ibb.co/CMFk540"

    and this image for including multipagewidget in ui_profile.h
    url :"https://ibb.co/gRJ8kCL"


  • Lifetime Qt Champion

    Hi
    Just as a note.
    There is also QStackedWidget which is a multi page widget.
    https://doc.qt.io/qt-5/qstackedwidget.html#details



  • @mrjj
    Yeah , i know QStackedWidget and used it in this Design but i've many stuff so i need multipagewidget to container these stuff in it and MultiPageWidget similar to QToolBox in containg the stuff and MultiPageWidget the Perfect solution here


  • Lifetime Qt Champion

    @MostafaEzzat
    Ok. fair enough.
    You are using the Qt5 version ? (seems so)
    C:\Qt\Examples\Qt-5.12.0\designer\containerextension
    I just tried open it in Creator and it just compiled and generated the .DLL ( the plugin)

    So are you trying to use this in Qt4 ?

    Im wondering why you get error as it just compiles here.

    Also it seems that you are adding the sources to your app ?
    And not create the SO file ( the plugin ) and copy it to designers plugin dir for it to load
    when run.
    So do you mean you want to use as a true plugin or simply use the Widget via promotion ?



  • @mrjj
    Thank you alot it works now , but just for curiosity why didn't it work with qt-qmake4 ?
    i've both qt4-qmake and qt5-qmake and compiled this widget with qt-qmake5 and worked and the errors was on qt-qmake4 .. so if i wanna compile it with qt-qmake4 what should i do?
    the widget after displaying : "https://ibb.co/wSZ9S7V"


  • Lifetime Qt Champion

    Hi
    Congrats, you fist Designer plugin :)
    Well with qt-qmake4 it would use Qt4 headers and stuff like QStringLiteral ( from Qt5.0) and QOverload (from Qt 5.7.)
    is not defined there.
    You can replace QStringLiteral with nothing and QOverload with static_cast
    with SIGNAL/SLOT macros.
    However, you could also just find the same sample in Qt4 samples.
    (it seems to have existed back there)

    Anyway, if you build and use the actual Designer plugin, im not sure Creator will load it (if compiled with Qt4)
    as Creator Qt5 based (unless its old version).

    You also need at Qt4 version besides the Qt5 version or why, if i may ask?



  • @MostafaEzzat

    Thank you alot it works now , but just for curiosity why didn't it work with qt-qmake4 ?

    • When you build with qt4-qmake you are compiling for Qt 4; when you build with qt5-qmake you are compiling for Qt 5.
    • There are changes in the Qt functions between Qt 4 and Qt 5.
    • Code written for one of these may not compile in the other.
    • You are using an example supplied with Qt 5 (-/usr/lib64/qt5/examples/designer/containerextension).
    • For example, I saw one of your error messages was 'windowTitleChanged' is not a member of 'QWidget'. Qt 5 documentation shows https://doc.qt.io/qt-5/qwidget.html#windowTitleChanged, and says "This function was introduced in Qt 5.2.". Qt 4 documentation https://doc.qt.io/archives/qt-4.8/qwidget.html shows it did not exist back then.
    • This means that line of code must have been added just for Qt 5.
    • If you try to compile that for Qt 4 it will error as you have seen.
    • You would need the code of that example as it was supplied in Qt 4 if you want to build for Qt 4. Or you have to make all necessary edits yourself.


  • @mrjj

    @mrjj said in Error in using MultiPageWidget from QtDesigner:

    Hi
    Congrats, you fist Designer plugin :)
    Well with qt-qmake4 it would use Qt4 headers and stuff like QStringLiteral ( from Qt5.0) and QOverload (from Qt 5.7.)
    is not defined there.
    You can replace QStringLiteral with nothing and QOverload with static_cast
    with SIGNAL/SLOT macros.
    However, you could also just find the same sample in Qt4 samples.
    (it seems to have existed back there)

    Anyway, if you build and use the actual Designer plugin, im not sure Creator will load it (if compiled with Qt4)
    as Creator Qt5 based (unless its old version).

    You also need at Qt4 version besides the Qt5 version or why, if i may ask?

    Sure , First of all thank you for your help

    in the first i had only qt4 then my OS (which is fedora 29) lost his grub and also Windows but i was owning my project when installed a new Systems , i faced many problems in connecting the database and so on so i downloaded qt4 then qt5 coz qt5 downloaded with all .so files of mysql but qt5 consumes too much memory while compiling and make the system freezing Especially with GNOME but the final project will be compiled in Qt5 (and i guess i've to sober in using Qt5 Libraries For Performance .. right ? or it included the main Libraries ? )



  • @JonB said in Error in using MultiPageWidget from QtDesigner:

    Thank you maybe i'll give it a try in someday ..


  • Lifetime Qt Champion

    @MostafaEzzat
    Hi
    Qt4 is really old so new development is best to do on Qt5.
    And all the new stuff comes in Qt5+. So yes, much more fun to use.

    How much memory do you have?



  • @mrjj
    i've 4 gb Ram when i use Qt5 and compile the code the memory usage reaches about 2.9 GB maybe more but i ain't know why only Qt5 make the system freezing (but i'll try the new upgrade of the system and see it again )


Log in to reply