[Solved] Signal wont emit



  • Hey,

    I have a little programm wich need to have a Error logging structure.
    I want to use Slots and Signals for this.

    So I first wrote a slot to my Handler class:

    @
    CHandler.h

    class CHandler : public QObject
    {
    Q_OBJECT
    [...]
    public slots:
    void ErrorHandler(framework::Diagnostics::LogLevel l, const char* c);
    [...]

    CHandler.cpp

    void CHandler::ErrorHandler(framework::Diagnostics::LogLevel l, const char *c){

    switch(l){
      [...]
    }
    

    }
    @

    Then I wrote the Signal:

    @
    class CDatabase : public QObject
    {
    Q_OBJECT
    [...]

    signals:
    void ErrorHandlerCallBack(framework::Diagnostics::LogLevel l, const char* c);
    @

    and connected them:

    @CHandler::CHandler()
    {
    Database = CDatabase::getInstanz();
    Database->OpenDatabaseConnection();

    CHandler::connect(Database, SIGNAL(ErrorHandlerCallBack(framework::Diagnostics::LogLevel,const char*)), this, SLOT(ErrorHandler(framework::Diagnostics::LogLevel,const char*)));
    

    @

    I emit the Signal by:

    @
    [...]
    QSqlError er = db.lastError();
    emit ErrorHandlerCallBack(framework::Diagnostics::LogLevel::ERR, er.databaseText().toStdString().c_str());
    [...]@

    But nothing happens.
    Can anyone see the misstake I did?


  • Lifetime Qt Champion

    Hi,

    Did you check whether you had an error message on the console when doing the connection ?

    Are you sure you are reaching the code where the signal is triggered ?

    Out of curiosity, why don't you use QString as your argument ?



  • bq. Did you check whether you had an error message on the console when doing the connection ?

    The connection succeedes properly.

    bq. Are you sure you are reaching the code where the signal is triggered ?

    Yes, Iam sure. I checked it twice.

    bq. Out of curiosity, why don’t you use QString as your argument ?

    There are diffrent situations where this function is called. Mostly there are given hardcoded strings to this function and to get the strings logged they have to be in const char*. So I just save some conversions there.



  • I Solved the Problem.

    I just reorganized the Code and do now the connection after the object is constructed. It seems that the connection doesnt work properly in the constructer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.