Results 1 to 5 of 5

Thread: binding to qInstallMessageHandler

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default binding to qInstallMessageHandler

    I want to use a class member as a handler for Qt output. Following code fails to compile; I'll appreciate a helping hand

    Qt Code:
    1. void test::debugOut(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    2. {
    3.  
    4. }
    5.  
    6. void test::onConnect()
    7. {
    8. auto fp = std::bind (&test::debugOut, *this, std::placeholders::_1);
    9. qInstallMessageHandler(fp);
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: binding to qInstallMessageHandler

    What about using a singleton and make the debugOut function a static that accesses the singleton instance?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    TorAn (21st December 2013)

  4. #3
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: binding to qInstallMessageHandler

    We live in the age of C++11 and new std, man.
    Following should compile, but does not and I can't figure out why.

    Qt Code:
    1. auto fp = std::bind (&test::debugOut, *this, std::placeholders::_1);
    2. qInstallMessageHandler(fp);
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: binding to qInstallMessageHandler

    Well, you are not giving us any error message, so trying to help with your actual problem is not an option.

    My guess is that the compiler doesn't like your attempt to bind *this as the QMsgType argument of the given function.

    I know it isn't C++11, man, but from a way older standard version, but maybe std::mem_fun() is what you are looking for?

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    TorAn (21st December 2013)

  7. #5
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: binding to qInstallMessageHandler

    First of all - thank you for your replies, I mean it!

    The error (VS2012, I'll upgrade to 13 tonight to see if it helps) is:

    error C2664: 'qInstallMessageHandler' : cannot convert parameter 1 from 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V 3_t,_V4_t,_V5_t,<unnamed-symbol>>' to 'QtMessageHandler'
    with
    [
    _Forced=true,
    _Ret=void,
    _Fun=std::_Pmf_wrap<void (__thiscall test::* )(QtMsgType,const QMessageLogContext &,const QString &),void,test,QtMsgType,const QMessageLogContext &,const QString &,std::_Nil,std::_Nil,std::_Nil,std::_Nil>,
    _V0_t=test &,
    _V1_t=std::_Ph<1> &,
    _V2_t=std::_Nil,
    _V3_t=std::_Nil,
    _V4_t=std::_Nil,
    _V5_t=std::_Nil,
    <unnamed-symbol>=std::_Nil
    ]
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Similar Threads

  1. Why qInstallMessageHandler not run on console app?
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2013, 11:37
  2. c++ and qml binding
    By ganeshgladish in forum Newbie
    Replies: 8
    Last Post: 8th May 2013, 14:19
  3. qt binding?
    By giugio in forum Qt Programming
    Replies: 4
    Last Post: 15th November 2012, 14:33
  4. binding text in QMl to c++
    By rajeshk.ict in forum Newbie
    Replies: 1
    Last Post: 16th March 2012, 08:40
  5. binding
    By mickey in forum General Discussion
    Replies: 9
    Last Post: 26th September 2006, 21:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.