victronenergy / QsLog

Forked from https://bitbucket.org/razvanpetru/qt-components/wiki/QsLog
Other
114 stars 78 forks source link

Connecting to signal or slot #4

Open inejose opened 2 years ago

inejose commented 2 years ago

Hi,

thanks for the library. We tried to connect DestinationPtr to an existing slot or signal, in order to print the logs in a specific area of a QMainWindows but get some errors.

The custom class slot implementation is:

void MyClass::onNewLog(const QString &msg, int level)
{
    //My Slot
}

The connection we tried is:

Logger& logger = Logger::instance();
logger.setLoggingLevel(QsLogging::TraceLevel);
const char *SLOTDESTINY = "onNewLog(QString,int)";
DestinationPtr slotDestination(DestinationFactory::MakeFunctorDestination(qobject_cast<QObject*>(this), SLOTDESTINY));

We received the error:

QObject::connect: Use the SLOT or SIGNAL macro to connect Logging::onNewLog(QString,int) We also tried to connect to a signal and some variations of the input arguments:

    DestinationPtr slotDestination(DestinationFactory::MakeFunctorDestination(this, "onNewLog(QString,int)"));
    DestinationPtr slotDestination(DestinationFactory::MakeFunctorDestination(this, "SLOT(onNewLog(QString,int))"));

Is there a way to connect logs to an external class by signal or slots qt functionality?

We use Qt 15.12.2. Examples work fine, but there is not an example for connecting to a member function or signal/slot.

Thanks in advance.