Results 1 to 13 of 13

Thread: possible to connect defined signals(available in Qt designer) to custom slots...?

  1. #1
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Question possible to connect defined signals(available in Qt designer) to custom slots...?

    Hi to all,
    I am having a doubt with regards to signals and slots... I was trying to connect spinboxes to the QCalendarWidget in Qt Designer (for user to edit the date, month and year) when I realise that the QCalendarWidget only has the following public slots...

    Public Slots
    void setCurrentPage ( int year, int month )
    void setDateRange ( const QDate & min, const QDate & max )
    void setSelectedDate ( const QDate & date )
    void showNextMonth ()
    void showNextYear ()
    void showPreviousMonth ()
    void showPreviousYear ()
    void showSelectedDate ()
    void showToday ()
    19 public slots inherited from QWidget
    1 public slot inherited from QObject

    So does it mean that i cannot connect the signal <void valueChanged ( int i )> of the QSpinBox to any of the slots (in Qt Designer) for the purpose of date/month/year editing? In that case, am I left with the only way, which is creating my own calendar widget with my own slots and connecting them(in code)? Or are there any better way out?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    Yes, you won't be able to connect to those slots directly in Designer. But you are using the widgets inside some form that will be put into some real widget that you'll have to create. You can implement custom slots for it and manipulate the calendar widget from within there - no need to subclass QCalendarWidget.

  3. #3
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    hihi again... tried doing it... so far I have only the .h file and it already has a weird error...
    here's the connectcalcombox.h and the error below... in the whole .pro file, I have 5 files, main.cpp, mainframe.cpp, mainframe.h, connectcalcombox.h and .cpp(empty), and a Qt Ui file, named mainframe. The main, mainframe files are there by default when I create a new project.

    Qt Code:
    1. #ifndef __CONNECTCALCOMBOX_H__
    2. #define __CONNECTCALCOMBOX_H__
    3.  
    4. #include <QWidget>
    5. class QComboBox;
    6. class QLabel;
    7. // place your code here
    8. class ConnectCalCombox : public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. ConnectCalCombox();
    14.  
    15. private slots:
    16. void dayDateChanged();
    17. void mthDateChanged();
    18. void yrDateChanged();
    19. void minTimeChanged();
    20. void hrTimeChanged();
    21.  
    22. private:
    23. QLabel *dateLabel;
    24. QLabel *dayDateLabel;
    25. QLabel *mthDateLabel;
    26. QLabel *yrDateLabel;
    27. QLabel *timeLabel;
    28. QLabel *minTimeLabel;
    29. QLabel *hrTimeLabel;
    30. QComboBox *dayDateComboBox;
    31. QComboBox *mthDateComboBox;
    32. QComboBox *yrDateComboBox;
    33. QComboBox *hrTimeComboBox;
    34. QComboBox *minTimeCOmboBox;
    35.  
    36. }
    37. #endif // __CONNECTCALCOMBOX_H__
    To copy to clipboard, switch view to plain text mode 

    ../../HMIDeveloper/Qt/include/QtCore/../../src/corelib/tools/qhash.h:51: error: `QtValidLicenseForCoreModule' does not name a type
    mingw32-make[1]: Leaving directory `C:/HmiProject/omg'
    mingw32-make[1]: *** [build\host\connectcalcombox.o] Error 1
    mingw32-make: *** [release] Error 2

    the error is gone when i comment out the whole part from
    "class ConnectCalCombox : public QWidget" onwards... Anyone can point out my problem? >.<
    Many thanks in advance.
    Last edited by mynahz; 16th June 2008 at 06:50.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    Which version of Qt are you using?

  5. #5
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    Currently using Qt 4.

    and there's another doubt i want to find out... if i want to set the choices in the combobox, i am not sure what to put in the 'xxx' part...

    dayDateCombobox->addItem(tr("01", xxx);

    i want to make it such that the selection in combo box will set the correct date in the QCalendar widget... How do i go abt doing this?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    Qt 4.x where x=?

  7. #7
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    ohoh... it's 4.3.2

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    The class declaration is missing ending semi-colon:
    Qt Code:
    1. class ConnectCalCombox
    2. {
    3. ...
    4. }; // <---
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. #9
    Join Date
    Jun 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    speaking of signals and slots.... can i connect my custom signals of a different class to the custom slots of a different class...??

  10. #10
    Join Date
    Jun 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    Quote Originally Posted by rick_st3 View Post
    speaking of signals and slots.... can i connect my custom signals of a different class to the custom slots of a different class...??
    Yes, if these 2 classes are derived from QObject (or from something, which is based on QObject).

    QObject::connect(<ptr to signaling class>, SIGNAL( someSignal() ), <ptr to slot class>, SLOT( someSlot() ) );

  11. #11
    Join Date
    Jun 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    actually i tried connecting two classes through custom signals and custom slots, one class was inheriting QWidget and the other was inheriting QGLWidget... but the connection was not working... now,is such a connection possible...??? if no please suggest some other alternative... thanks...

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    Quote Originally Posted by rick_st3 View Post
    actually i tried connecting two classes through custom signals and custom slots, one class was inheriting QWidget and the other was inheriting QGLWidget... but the connection was not working... now,is such a connection possible...??? if no please suggest some other alternative... thanks...
    Yes, it is possible. Just make sure that both class declarations contain required Q_OBJECT macro and that you declare signals and slots properly. Take a look at the debug output. QObject::connect() outputs a detailed warning when it fails to establish signal-slot connection.
    J-P Nurmi

  13. #13
    Join Date
    Jun 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: possible to connect defined signals(available in Qt designer) to custom slots...?

    got it... thanx mate...

Similar Threads

  1. Replies: 2
    Last Post: 12th July 2007, 09:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.