PDA

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



mynahz
13th June 2008, 03:55
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)?:eek: Or are there any better way out?

wysota
13th June 2008, 07:11
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.

mynahz
16th June 2008, 06:45
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.


#ifndef __CONNECTCALCOMBOX_H__
#define __CONNECTCALCOMBOX_H__

#include <QWidget>
class QComboBox;
class QLabel;
// place your code here
class ConnectCalCombox : public QWidget
{
Q_OBJECT

public:
ConnectCalCombox();

private slots:
void dayDateChanged();
void mthDateChanged();
void yrDateChanged();
void minTimeChanged();
void hrTimeChanged();

private:
QLabel *dateLabel;
QLabel *dayDateLabel;
QLabel *mthDateLabel;
QLabel *yrDateLabel;
QLabel *timeLabel;
QLabel *minTimeLabel;
QLabel *hrTimeLabel;
QComboBox *dayDateComboBox;
QComboBox *mthDateComboBox;
QComboBox *yrDateComboBox;
QComboBox *hrTimeComboBox;
QComboBox *minTimeCOmboBox;

}
#endif // __CONNECTCALCOMBOX_H__

../../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. :)

wysota
16th June 2008, 07:03
Which version of Qt are you using?

mynahz
16th June 2008, 07:19
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? :confused:

wysota
16th June 2008, 09:40
Qt 4.x where x=? :)

mynahz
17th June 2008, 01:49
:D ohoh... it's 4.3.2

jpn
17th June 2008, 20:29
The class declaration is missing ending semi-colon:


class ConnectCalCombox
{
...
}; // <---

rick_st3
20th June 2008, 09:04
speaking of signals and slots.... can i connect my custom signals of a different class to the custom slots of a different class...??

Holy Cheater
21st June 2008, 18:55
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() ) );

rick_st3
23rd June 2008, 06:53
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...

jpn
23rd June 2008, 07:02
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.

rick_st3
23rd June 2008, 08:05
got it... thanx mate...