Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Signal wont emit
Qt 6.11 is out! See what's new in the release blog

[Solved] Signal wont emit

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dropye
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dropye
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dropye
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved