2

I have following method for debug purposes:

void UeLoggedUsersInfo::uePrintLoggedUsers()
{
    qDebug() << "\n"
             << Q_FUNC_INFO
             << ":\n";
    for(int index=0; index<this->ueLoggedUsersData()->size(); index++)
    {
        qDebug() << this->ueLoggedUsersData()->at(index).constBegin().key().first
                 << this->ueLoggedUsersData()->at(index).constBegin().key().second
                 << this->ueLoggedUsersData()->at(index).constBegin().value();
    }   // for

    qDebug() << "\nEND\n";
}   // uePrintLoggedUsers

It traverses across some data structure and prints its mebmers values, that is all ok. But, is it possible with Qt framework (without including other frameworks) to print within this method which method is calling it and if it is, how?

KernelPanic
  • 2,328
  • 7
  • 47
  • 90
  • 4
    take a look at printing the call stack: http://stackoverflow.com/questions/3899870/print-call-stack-in-c-or-c. There's no portable way to do it. qcrashhandler.cpp may also provide some useful information. You can find it at ${QTDIR}/Src/qtbase/stc/corelib/kernel. – Nicolas Holthaus Dec 15 '15 at 15:39
  • @Kuba Ober the question is not C/C++, but Qt oriented, I was asking if it is possible to do it using Qt framework only. – KernelPanic Dec 15 '15 at 16:17
  • Any answers as to whether Qt might help out there belong in the duplicate question - Qt is a C++ framework, after all. Qt provides no such functionality anyway. Normally you'd use a crash reporting framework and debug symbol files to figure such things out. – Kuba hasn't forgotten Monica Dec 15 '15 at 16:25
  • 1
    You can define a `QtMessageHandler`; install it with `qInstallMessageHandler` (see its docs). The `QMessageLogContext` your handler receives is populated with `file`, `line` and `function` members. – Toby Speight Dec 15 '15 at 16:25
  • @TobySpeight This does nothing to help with obtaining and decoding stack traces... – Kuba hasn't forgotten Monica Dec 15 '15 at 16:26
  • 1
    @Kuba - the linked question asks for a full backtrace; this question merely requires identification of the (immediate) calling function. My comment wouldn't be an answer to that question. – Toby Speight Dec 15 '15 at 16:27
  • What about providing Q_FUNC_INFO as an argument of uePrintLoggedUsers to be provided by the calling function? – Tob Dec 20 '18 at 07:45

0 Answers0