Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QSqlRelationalDelegate

[SOLVED] QSqlRelationalDelegate

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Al79
    wrote on last edited by
    #1

    Hi all,

    i have some trouble using QSqlRelationalDelegate with last qt version: 5.0.1.

    I wrote this code, that works with qt-4.8:
    @
    //scadenze.h:
    #ifndef SCADENZE_H
    #define SCADENZE_H

    class QTableView;
    class QSqlRelationalTableModel;
    class QSqlDatabase;

    #include "database.h"

    class Scadenze
    {
    public:
    Scadenze();
    private:
    void initModel();
    void NewStabili();

    Database *m_database;
    QTableView *table;
    QSqlRelationalTableModel *model;
    

    };

    #endif // SCADENZE_H
    @

    @
    //scadenze.cpp:
    #include "scadenze.h"

    #include <QtWidgets/QTableView>
    #include <QSqlRelationalTableModel>
    #include <QSqlDatabase>
    #include <QtWidgets/QHeaderView>
    //i tried with: #include <QSqlRelationalDelegate> too:
    #include <QtSql/QSqlRelationalDelegate>

    Scadenze::Scadenze()
    {
    //stabili = new Stabili();
    //showtables = new ShowTables();

    m_database = new Database();
    m_database->connection();
    m_database->createTables();
    
    initModel();
    
    table = new QTableView();
    table->setModel(model);
    table->setItemDelegate(new QSqlRelationalDelegate(table));//line 30
    table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    table->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    

    }
    [...]
    @

    @
    //compiler error:
    15:26:26: Running steps for project scadenziario...
    15:26:26: Configuration unchanged, skipping qmake step.
    15:26:26: Starting: "C:\Qt\Qt5.0.1\Tools\MinGW\bin\mingw32-make.exe"
    C:/Qt/Qt5.0.1/Tools/MinGW/bin/mingw32-make -f Makefile.Release
    mingw32-make[1]: Entering directory 'C:/Users/user/Dropbox/Programmi/Qt/scadenziario-build-Desktop_Qt_5_0_1_MinGW_32bit-Release'
    g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I..\Scadenziario -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include" -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtSql" -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui" -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtCore" -I"build\moc" -I"." -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspecs\win32-g++" -o build\o\scadenze.o ..\Scadenziario\scadenze.cpp
    ..\Scadenziario\scadenze.cpp: In constructor 'Scadenze::Scadenze()':
    ..\Scadenziario\scadenze.cpp:30:32: error: expected type-specifier before 'QSqlRelationalDelegate'
    ..\Scadenziario\scadenze.cpp:30:32: error: expected ')' before 'QSqlRelationalDelegate'
    ..\Scadenziario\scadenze.cpp:30:61: error: no matching function for call to 'QTableView::setItemDelegate(int*)'
    ..\Scadenziario\scadenze.cpp:30:61: note: candidate is:
    In file included from ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtWidgets/qtableview.h:45:0,
    from ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtWidgets/QTableView:1,
    from ..\Scadenziario\scadenze.cpp:11:
    ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtWidgets/qabstractitemview.h:134:10: note: void QAbstractItemView::setItemDelegate(QAbstractItemDelegate*)
    ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtWidgets/qabstractitemview.h:134:10: note: no known conversion for argument 1 from 'int*' to 'QAbstractItemDelegate*'
    Makefile.Release:1769: recipe for target 'build/o/scadenze.o' failed
    mingw32-make[1]: *** [build/o/scadenze.o] Error 1
    mingw32-make[1]: Leaving directory 'C:/Users/user/Dropbox/Programmi/Qt/scadenziario-build-Desktop_Qt_5_0_1_MinGW_32bit-Release'
    makefile:34: recipe for target 'release' failed
    mingw32-make: *** [release] Error 2
    15:26:30: The process "C:\Qt\Qt5.0.1\Tools\MinGW\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project scadenziario (kit: Desktop Qt 5.0.1 MinGW 32bit)
    When executing step 'Make'
    @

    Thanks in advance for your help.
    Al

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Al79
      wrote on last edited by
      #2

      A further note:

      qt docs says that my code should work:

      "http://qt-project.org/doc/qt-5.0/qtsql/qsqlrelationaltablemodel.html#details":http://qt-project.org/doc/qt-5.0/qtsql/qsqlrelationaltablemodel.html#details

      and qtcreator itself confirm the same stuff:

      !http://i.imgur.com/iL2UbAd.png?1(qt.png)!

      if i forget some details please let me know...
      thanks for your help and time in advance.
      Al

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hostel
        wrote on last edited by
        #3

        Have you in *.pro file:
        @
        QT += widgets sql
        @
        ?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          You error messsage clearly indicates that QSqlRelationalDelegate is an unknow type, which is caused by a missing header file (although you obviously do not miss it).

          It is actually quite easy to find out if the type is known, just place the cursor over QSqlRelationalDelegate and press F2 (Follow Symbol Under Cursor). If you can follow it (you will be taken to the class definition) it is known and I would suggest to rebuild your whole project. If you cannot there might be something wrong with your headers.

          In this case, please post a small compilable example which reproduces your problem, so we can take a closer look at it.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Al79
            wrote on last edited by
            #5

            Hi Hostel and thanks for your replay.

            Your advice solved, or to be clearer, now I have some other compilation troubles.

            My full .pro file:

            @
            QT += core gui sql widgets
            TARGET = scadenziario
            TEMPLATE = app

            SOURCES += main.cpp
            mainwindow.cpp
            database.cpp
            scadenze.cpp
            stabilidialog.cpp
            messagedialog.cpp
            percentualedialog.cpp
            itemdelegate.cpp
            afferenze.cpp
            persone.cpp
            utility.cpp
            personadialog.cpp
            fornitoridialog.cpp
            recapitidialog.cpp

            HEADERS += mainwindow.h
            database.h
            scadenze.h
            stabilidialog.h
            messagedialog.h
            percentualedialog.h
            itemdelegate.h
            afferenze.h
            persone.h
            utility.h
            personadialog.h
            fornitoridialog.h
            recapitidialog.h

            FORMS += stabilidialog.ui
            messagedialog.ui
            percentualedialog.ui
            afferenze.ui
            persone.ui
            personadialog.ui
            fornitoridialog.ui
            recapitidialog.ui

            RESOURCES += resources.qrc
            @

            @//mainwindow.cpp:
            QMdiSubWindow *w;
            QAction *act;
            StabiliDialog *m_stab = new StabiliDialog(m_database,this);
            connect(m_stab,SIGNAL(rejected()),this,SLOT(closeActiveSubWindow()));
            m_stabili.push_back(m_stab);

            w = mdiArea->addSubWindow(m_stab);
            //creo una QAction per ripristinare la finestra relativa:
            act = new QAction("Stabili",this);
            stabiliMenu->addAction(act);
            m_stab->setUserData(0,(QObjectUserData *)act);
            connect(act,SIGNAL(triggered()),w,SLOT(showNormal()));//line 331
            connect(act,SIGNAL(triggered()),w,SLOT(setFocus()));//line 332
            

            @

            @
            ..\Scadenziario\mainwindow.cpp: In member function 'StabiliDialog* MainWindow::createStabile()':
            ..\Scadenziario\mainwindow.cpp:331:57: error: no matching function for call to 'MainWindow::connect(QAction*&, const char*, QMdiSubWindow*&, const char*)'
            ..\Scadenziario\mainwindow.cpp:331:57: note: candidates are:
            In file included from ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qabstractanimation.h:45:0,
            from ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/QtCore:4,
            from ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui/QtGui:4,
            from ..\Scadenziario\mainwindow.cpp:9:
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:211:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:211:36: note: no known conversion for argument 3 from 'QMdiSubWindow*' to 'const QObject*'
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:214:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:214:36: note: no known conversion for argument 2 from 'const char*' to 'const QMetaMethod&'
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:430:32: note: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:430:32: note: no known conversion for argument 3 from 'QMdiSubWindow*' to 'const char*'
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:227:43: note: template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func1>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType)
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h:227:43: note: template argument deduction/substitution failed:
            ............\Qt\Qt5.0.1\5.0.1\mingw47_32\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func1>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = const char*; Func2 = const char*]':
            ..\Scadenziario\mainwindow.cpp:331:57: required from here
            @

            Thanks for your help.
            Al

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hostel
              wrote on last edited by
              #6

              In Qt 5 we have a "new signal slot syntax":http://qt-project.org/wiki/New_Signal_Slot_Syntax. Rewrite connect().

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Al79
                wrote on last edited by
                #7

                Nice to know.
                Thanks,
                Al

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Al79
                  wrote on last edited by
                  #8

                  Ok i tried and it works even with some problems...maybe it depends on connects I do not modified yet. I changed only the first connect(line 331) and now it compiles and runs properly.

                  Anyway I can't understand, from your link:

                  bq. "Qt5 will continue to support the old string-based syntax [doc.qt.nokia.com] for connecting signals and slots defined in a QObject or any class that inherits from QObject (including QWidget)"

                  If Qt5 support old connect, why I need to modify my (qt-4.8.X) working code?
                  At line 331 I'm connecting a QAction to a QMdiSubWindow and both come from QObject...

                  Thanks for support.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    Hostel
                    wrote on last edited by
                    #9

                    Hmm strange. Maybe you forgot to include the QAction and QMdiSubWindow?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Al79
                      wrote on last edited by
                      #10

                      Yes. you was right.
                      Thanks for your precious support.
                      Al

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved