Results 1 to 18 of 18

Thread: Ui file loaded by UiLoader , but NULL pointer to custom widgets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    2

    Question Ui file loaded by UiLoader , but NULL pointer to custom widgets

    Hello, i am using Qt 4.7.0 and windows7,
    i have a Huge problem with custom widgets, i founded QLed custom widget,from:
    http://qt-apps.org/content/show.php?content=72482
    i use it.

    i want to add a signal properties to QLed widget and in design time with QtDesigner i want to add 100 QLed's on my Ui file
    and set each QLed's signal properties to a number(type of signal properties is not important), so i want to access this 100 QLeds
    when i am coding and make a QList and access those

    Qt Code:
    1. QFile file(":/test.ui");
    2. QUiLoader loader;
    3. file.open(QFile::ReadOnly);
    4. QWidget *formWidget = loader.load(&file, this);
    5. file.close();
    6. formWidget->show();
    7. QList<QLed *> allQLed = formWidget->findChildren<QLed *>();
    8.  
    9. //now i want to send data to QLeds
    10.  
    11. for(int i=0; i<allQLed.size(); i++){
    12. if(allQLed.at(i)->SIGNAL_PROPERTIES() == 123)
    13. allQLed.at(i)->setValue(true);
    14. else
    15. allQLed.at(i)->setValue(false);
    16. }
    17. // now it will ON all QLeds that SIGNAL_PROPERTIES == 123
    To copy to clipboard, switch view to plain text mode 
    //__________________________________________________ _________
    //__________________________________________________ _________
    //__________________________________________________ _________
    is my metod incorect or i can do in other way?
    i wrote my problem step by step
    i changed dialog.cpp and cunstructor Dialog::Dialog(QWidget *parent) : and *.pro file
    i attached my test program.
    THANKs in ADVANCE.
    //__________________________________________________ _________
    //__________________________________________________ _________
    //__________________________________________________ _________
    i copied qledplugin-build-desktop\release folder files: qledplugin.dll,
    libqledplugin.a,
    moc_qled.cpp,
    moc_qledplugin.cpp,
    qrc_qled.cpp,
    moc_qled.o,
    moc_qledplugin.o,
    qled.o,
    qledplugin.o,
    qrc_qled.o,

    to:
    1) C:\QledTEST\my test program\mytest-build-desktop
    2) C:\QledTEST\my test program\mytest-build-desktop\release
    3) C:\QledTEST\my test program\mytest-build-desktop\debug
    4) C:\Qt\2010.05\qt\include\QtGui
    5) C:\Qt\2010.05\qt\include\Qt
    6) C:\Qt\2010.05\qt\lib
    7) C:\Qt\2010.05\qt\plugins\designer
    , i can design a Ui dialog with QtDesigner and placing QLeds and QLabels, every thing is good, and i also can use other widgets. after it, i want to show this Ui file in my program, i am using UiLoader, i load Ui file in a QWidget object
    QWidget *formWidget = loader.load(&file, this);
    and .show() it,
    in compile time i get this warnings in 1)Build Issues tab:

    release/moc_qled.cpp:75: warning: 'QLed::staticMetaObject' redeclared without dllimport attribute after being referenced with dll linkage
    release/moc_qled.cpp:84: warning: 'virtual const QMetaObject* QLed::metaObject() const' redeclared without dllimport attribute: previous dllimport ignored
    release/moc_qled.cpp:89: warning: 'virtual void* QLed::qt_metacast(const char*)' redeclared without dllimport attribute: previous dllimport ignored
    release/moc_qled.cpp:97: warning: 'virtual int QLed::qt_metacall(QMetaObject::Call, int, void**)' redeclared without dllimport attribute: previous dllimport ignored
    but my program work.
    every thing is good, and my designed file is loading.
    i use this command:
    qDebug() << formWidget->children();
    and i can see in 3) Application Output tab:

    Starting C:\QledTEST\my test program\mytest-build-desktop\release\example.exe...
    (QFormInternal::TranslationWatcher(0x14683d8) , QLed(0x1472320, name = "qLed_2") , QLed(0x14722a0, name = "qLed_3") , QLed(0x14723a0, name = "qLed_4") , QCheckBox(0x14810b8, name = "checkBox_2") , QCheckBox(0x14810d8, name = "checkBox_3") , QCheckBox(0x14810f8, name = "checkBox_4") , QLabel(0x1481118, name = "label") , QCheckBox(0x1481138, name = "checkBox") , QLed(0x14724e0, name = "qLed") )
    C:\QledTEST\my test program\mytest-build-desktop\release\example.exe exited with code 0
    so i can see formWidget children, that containes QLeds my Custom Widgets.

    now i need to send data to my QLeds and QCheckBoxs,
    i make a QList and try it:

    Qt Code:
    1. QList<QCheckBox *> allCheckBox = formWidget->findChildren<QCheckBox *>();
    2. qDebug() << allCheckBox;
    3. qDebug() << allCheckBox.size();
    4. allCheckBox.at(2)->setChecked(true); // i can send data
    5. QCheckBox *hello1=formWidget->findChild<QCheckBox*>("checkBox_2");
    6. qDebug() << hello1;
    7. hello1->setChecked(true);// i can send data
    To copy to clipboard, switch view to plain text mode 
    i get:
    (QCheckBox(0x14e10b8, name = "checkBox_2") , QCheckBox(0x14e10d8, name = "checkBox_3") , QCheckBox(0x14e10f8, name = "checkBox_4") , QCheckBox(0x14e1138, name = "checkBox") )
    4
    QCheckBox(0x6f10b8, name = "checkBox_2")

    it showes 4 QCheckBox
    now i try Custom Widget:
    Qt Code:
    1. QList<QLed *> allQLed = formWidget->findChildren<QLed *>();
    2. qDebug() << allQLed;
    3. qDebug() << allQLed.size();
    To copy to clipboard, switch view to plain text mode 
    i get:
    ()
    0
    QObject(0x0) //null pointer
    my HUGE problem is here:
    allQLed.size() is zero
    and i get null pointers

    if i add QLed widget with coding i have no problem BUT i need QtDesigner.

    why this happend and what can i do?
    Qt cant do this?

    thanks in advance
    cheers
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    Are you QLed objects direct children of the form, or do they have a parent which it self is a child of the form?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    2

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    thanks high_flyer for reply, i think those are direct children,
    and my problem is still my previous post here:

    http://www.qtcentre.org/threads/4123...rogram-crashed

    so please download "my test program.zip‎" and check it, thanks in advance.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    i think those are direct children,
    "think" is not good enough.
    You have to be sure.
    I am sorry, but I have no possibility (here) to download and check your code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    2

    Smile Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    ok, in QtDesigner i add four QLed widgets to a form, so i think its direct child, i dont use a QLed in a QFrame.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    release/moc_qled.cpp:75: warning: 'QLed::staticMetaObject' redeclared without dllimport attribute after being referenced with dll linkage
    release/moc_qled.cpp:84: warning: 'virtual const QMetaObject* QLed::metaObject() const' redeclared without dllimport attribute: previous dllimport ignored
    release/moc_qled.cpp:89: warning: 'virtual void* QLed::qt_metacast(const char*)' redeclared without dllimport attribute: previous dllimport ignored
    release/moc_qled.cpp:97: warning: 'virtual int QLed::qt_metacall(QMetaObject::Call, int, void**)' redeclared without dllimport attribute: previous dllimport ignored
    It looks you have problem with your QLed library export/import, either the QLed class it self or the plugin.
    Did you define the export macro when building the QLed plugin?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    2

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    it is custom widget plugin for QtDesigner and contains Q_EXPORT_PLUGIN2(customwidgetplugin, QLedPlugin) .

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    you didn't answer my question, did you understand what I asked?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    2

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    QLed is a custom widget in QLed.h file exist :
    class QDESIGNER_WIDGET_EXPORT QLed : public QWidget
    Is this your answer !!??

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    Partly.
    This define either will expand to __declspec( dllimport ) or __declspec( dllexport ), depending if you define the define variable in your plugin project.
    In your plugin you should have a header with something like:
    Qt Code:
    1. #if defined(FOO_LIBRARY)
    2. # define FOOSHARED_EXPORT Q_DECL_EXPORT
    3. #else
    4. # define FOOSHARED_EXPORT Q_DECL_IMPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    and you have to define FOO_LIBRARY in your plugin project, otherwise the class doesn't get exported.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    2

    Default Re: Ui file loaded by UiLoader , but NULL pointer to custom widgets

    Hello high_flyer, thanks for replies,
    Dear Sir, Qts manual says i can design a custom widget and make a dll also plugin export what it need, and use it in QtDesigner, i think you say i make new other dll for using in QtCreator, but then is it possible two dll and same QLed class??

    i also tested this on Q3Frame it is a custom widget plugin in QtDesigner and same problem.

Similar Threads

  1. Replies: 21
    Last Post: 8th June 2011, 08:59
  2. Replies: 33
    Last Post: 2nd December 2010, 16:47
  3. Custom QLineEdit to store NULL with QDataWidgetMapper
    By certqt in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2010, 13:15
  4. Replies: 1
    Last Post: 28th June 2010, 06:21
  5. Dereferencing a NULL Pointer for staticMetaObject?
    By hyling in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 00:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.