diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2540cb18b7..2a88d3d2df 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2012-05-24 12:15 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/qtcore/hbqt_pointer.cpp + + Added: HB_FUNC( SIGNAL2SLOT ) which simulates exactly Qt's way + of signal/slot mechanism. Now hbQT has yet another way to + mimic signal/slots. + + + contrib/hbqt/tests/signalslots.prg + + Added: deno program to demonstrate Qt's way of signal/slot + affinity in Harbour. + + NOTE: above contribution is made by Francessco Perrilo, thanks. + 2012-05-24 14:35 UTC+0200 Viktor Szakats (harbour syenar.net) * contrib/hbtip/ftpcli.prg ! fixed item deletion inside FOR EACH loop (regression from diff --git a/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp b/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp index 245d26697e..638d0e8333 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_pointer.cpp @@ -456,6 +456,69 @@ HB_BOOL hbqt_par_isDerivedFrom( int iParam, const char * pszClsName ) return HB_FALSE; } +int hbqt_QtConnect( QObject *sender, const char * pszSignal, QObject *receiver, const char * pszSlot ) +{ + HB_TRACE( HB_TR_DEBUG, ( "_Connect %s with slot %s", pszSignal, pszSlot ) ); + + int nResult = 1; + + if( sender && receiver ) + { + QString signal = pszSignal; + QByteArray theSignal = QMetaObject::normalizedSignature( signal.toAscii() ); + QString slot = pszSlot; + QByteArray theSlot = QMetaObject::normalizedSignature( slot.toAscii() ); + + if( QMetaObject::checkConnectArgs( theSignal, theSlot ) ) + { + int signalId = sender->metaObject()->indexOfSignal( theSignal ); + if( signalId != -1 ) + { + int slotId = receiver->metaObject()->indexOfMethod( theSlot ); + if( slotId != -1 ) + { + if( QMetaObject::connect( sender, signalId, receiver, slotId, Qt::AutoConnection ) ) + { + nResult = 0; + HB_TRACE( HB_TR_DEBUG, ( "SIGNAL2SLOT ok" ) ); + } + else + nResult = 8; + } + else + nResult = 7; + } + else + nResult = 6; + } + else + nResult = 5; + } + else + nResult = 9; // Qt objects not active + + HB_TRACE( HB_TR_DEBUG, ( "_Connect returns: %d", nResult ) ); + return nResult; +} + +HB_FUNC( SIGNAL2SLOT ) +{ + HB_BOOL ret = HB_FALSE; + + if( hb_pcount() == 4 && HB_ISCHAR( 2 ) && HB_ISCHAR( 4 ) && hbqt_par_isDerivedFrom( 1, "QOBJECT" ) && hbqt_par_isDerivedFrom( 3, "QOBJECT" ) ) + { + void * pText01 = NULL; + void * pText02 = NULL; + if( hbqt_QtConnect( ( QObject* ) hbqt_par_ptr( 1 ), hb_parstr_utf8( 2, &pText01, NULL ), ( QObject* ) hbqt_par_ptr( 3 ), hb_parstr_utf8( 4, &pText02, NULL ) ) == 0 ) + { + ret = HB_TRUE; + } + hb_strfree( pText01 ); + hb_strfree( pText02 ); + } + hb_retl( ret ); +} + /*----------------------------------------------------------------------*/ #endif diff --git a/harbour/contrib/hbqt/tests/signalslots.prg b/harbour/contrib/hbqt/tests/signalslots.prg new file mode 100644 index 0000000000..0652c4e7b1 --- /dev/null +++ b/harbour/contrib/hbqt/tests/signalslots.prg @@ -0,0 +1,38 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Copyright 2012 Francessco Perillo + */ + +#include "hbqtgui.ch" + +PROCEDURE main() + LOCAL oMain, oLabel, oScrollBar, oLayout + + oMain := QWidget() + oMain:setMinimumHeight( 300 ) + oMain:setMinimumHeight( 300 ) + + oLayout := QVBoxLayout( oMain ) + + oScrollBar := QScrollBar( ) + + oLabel := QLabel( ) + oLabel:show() + oLabel:setText("Move the slider") + + oLayout:addWidget( oScrollBar ) + oLayout:addWidget( oLabel ) + + SIGNAL2SLOT( oScrollBar, "valueChanged(int)", oLabel, "setNum(int)" ) + + oMain:show() + + QApplication():exec() + + RETURN +