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. QStyledItemDelegate from library
Qt 6.11 is out! See what's new in the release blog

QStyledItemDelegate from library

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.4k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cultivation
    wrote on last edited by
    #1

    Hi,

    I am using a Subclass of QStyledItemDelegate named : EuroFormat. It is placed in a Library.
    When using the EuroFormat i am getting a segmenation fault.

    What am i doing wrong? can QStyledItemDelegate not be in another library?

    Added an example. A executable with Dll.
    "http://speedy.sh/ScUDg/TestApplication.zip":http://speedy.sh/ScUDg/TestApplication.zip "or dropbox":https://www.dropbox.com/s/1vlmiaccjkpnfyh/TestApplication.zip
    Any help is appreciated, thanks.

    1 Reply Last reply
    0
    • francescmmF Offline
      francescmmF Offline
      francescmm
      wrote on last edited by
      #2

      I'm currently using Delegates inside libraries, so its not the problem.

      Could you post the code when the EuroFormat() is created and called?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cultivation
        wrote on last edited by
        #3

        zip contains an example

        Here the code from the example

        @
        *.pro

        ....

        DEPENDPATH += . EuroFormat
        INCLUDEPATH += EuroFormat
        LIBS+= -LEuroFormat/release -lEuroFormat

        ....
        @

        @
        main.cpp

        #include "euroformat.h" //include from library

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);

        QTableView view;
        QStandardItemModel model(1,1);
        model.setData(model.index(0,0),10);
        view.setModel(&model);
        view.show();
        QAbstractItemDelegate* del = new EuroFormat;
        
        view.setItemDelegateForColumn(0, del);
        
        return a.exec();
        delete del;
        

        }@

        @
        EuroFormat.h + cpp + global

        #include <QtCore/qglobal.h>
        #include <QStyledItemDelegate>

        #if defined(EUROFORMAT_LIBRARY)

        define EUROFORMATSHARED_EXPORT Q_DECL_EXPORT

        #else

        define EUROFORMATSHARED_EXPORT Q_DECL_IMPORT

        #endif

        class EUROFORMATSHARED_EXPORT EuroFormat : public QStyledItemDelegate
        {
        Q_OBJECT

        public:
        explicit EuroFormat(QObject *parent = 0) : QStyledItemDelegate(parent){}
        virtual ~EuroFormat(){}

        virtual QString displayText(const QVariant &value, const QLocale &locale) const {
        

        return QString("€ %1").arg(locale.toString(value.toDouble(), 'f', 2));
        }
        };
        @

        1 Reply Last reply
        0
        • francescmmF Offline
          francescmmF Offline
          francescmm
          wrote on last edited by
          #4

          Yesterday I run your code and it compiles and runs a lot of times well. The problem is that some times it crashes when is executed a.exec(). With VisualStudio debugger it tells that the library was not well created.

          I don't know why it doesn't work, today I'll take a look using the .lib to ensure that is not the delegate.

          When I used the libraries with delegates I was done it with .lib not with .dll.

          1 Reply Last reply
          0
          • francescmmF Offline
            francescmmF Offline
            francescmm
            wrote on last edited by
            #5

            I confirm that using .lib there is no problems!

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cultivation
              wrote on last edited by
              #6

              Someone else told me that the code works fine under Unix.

              I am using Qt 5.0.1 under windows.

              So the library is fine. what could be causing this?

              wild guess: Is the delegation object created in another threat?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cultivation
                wrote on last edited by
                #7

                sort of stack trace

                UNADDRESSABLE ACCESS: reading 0x00000000-0x00000004 4 byte(s)
                0 Qt5Gui.dll!ZNK22QGuiApplicationPrivate15isWindowBl ockedEP7QWindowPS1_ +0x51b (0x61955ddb <Qt5Gui.dll+0x15ddb>)
                1 Qt5Gui.dll!ZN15QGuiApplication4fontEv +0x17 (0x619577b8 <Qt5Gui.dll+0x177b8>)
                2 Qt5Gui.dll!ZN5QFontC1Ev +0x18 (0x619d9bd9 <Qt5Gui.dll+0x99bd9>)
                3 Qt5Widgets.dll!ZN12QStyleOptionC2Eii +0x4b (0x11351b0c <Qt5Widgets.dll+0x61b0c>)
                4 Qt5Widgets.dll!ZN20QStyleOptionViewItemC1ERKS_ +0x26 (0x11646987 <Qt5Widgets.dll+0x356987>)
                5 Qt5Widgets.dll!ZNK19QStyledItemDelegate5paintEP8QP ainterRK20QStyleOptionViewItemRK11QModelIndex+0x1f (0x1157ee40 <Qt5Widgets.dll+0x28ee40>)
                6 Qt5Widgetsd.dll!QTableView:aintEvent() [itemviews/qtableview.cpp:1439]
                7 Qt5Widgetsd.dll!QWidget::event() [kernel/qwidget.cpp:7986]
                8 Qt5Widgetsd.dll!QFrame::event() [widgets/qframe.cpp:534]
                9 Qt5Widgetsd.dll!QAbstractScrollArea::viewportEvent () [widgets/qabstractscrollarea.cpp:1163]
                10 Qt5Widgetsd.dll!QAbstractItemView::viewportEvent() [itemviews/qabstractitemview.cpp:1679]
                11 Qt5Widgetsd.dll!QAbstractScrollAreaPrivate::viewpo rtEvent() [../../include/QtWidgets/5.0.1/QtWidgets/private/../../../../../src/widgets/widgets/qabstractscrollarea_p.h:105]
                Note: instruction: mov (

                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