Results 1 to 10 of 10

Thread: Redirect printf to QTextEdit?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Redirect printf to QTextEdit?

    Because we had a huge code base (10M lines C code)
    we wrote a wrapper around all of this as a single class.
    Now this class obvious has the information, warning and error singals
    defined in them.

    From there it can be used throughout the code as any other class would be.
    We needed to write little wrapper routines such that the emits could be
    called inside our C code but that was not to difficult.

    Again it is not the cleanest solution, however it did the trick with minimal
    modification to our original code base.

    If wanted I can post a little snippet of our code.
    (I don't have acces to the code right now)
    Otto Meijer
    email: otto.meijer@synopsys.com

  2. #2
    Join Date
    Aug 2006
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Redirect printf to QTextEdit?

    Quote Originally Posted by cwomeijer View Post
    Because we had a huge code base (10M lines C code)
    we wrote a wrapper around all of this as a single class.
    Now this class obvious has the information, warning and error singals
    defined in them.

    From there it can be used throughout the code as any other class would be.
    We needed to write little wrapper routines such that the emits could be
    called inside our C code but that was not to difficult.

    Again it is not the cleanest solution, however it did the trick with minimal
    modification to our original code base.

    If wanted I can post a little snippet of our code.
    (I don't have acces to the code right now)
    That would be really nice, it's always intresting to view other solutions.
    The above code actually works (to my surprise), tried it today in my application. And it works for both std::cout and printf's but not qDebug. It still needs some work though.

  3. #3
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Redirect printf to QTextEdit?

    Here is the code we use inside the class:

    void CatsCore::makeSignal(int type, char *str)
    {
    QString msg(str);

    switch (type) {
    default:
    case 0:
    emit information(msg);
    break;
    case 1:
    emit warning(msg);
    break;
    case 2:
    emit error(msg);
    break;
    case 3:
    emit progress(msg);
    break;
    }
    }
    }

    extern "C" void emitInfo(char *str)
    {
    Cats::globalCats->makeSignal(0,str);
    }

    extern "C" void emitWarning(char *str)
    {
    Cats::globalCats->makeSignal(1,str);
    }

    extern "C" void emitError(char *str)
    {
    Cats::globalCats->makeSignal(2,str);
    }

    extern "C" void emitProgress(char *str)
    {
    Cats::globalCats->makeSignal(3,str);
    }


    Because there can only be one Cats class we use the Cats::globalCats
    to get a hold of the instance.
    Otto Meijer
    email: otto.meijer@synopsys.com

Similar Threads

  1. a question about visualizing cursor in read-only QTextEdit
    By kennyxing in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2006, 19:52
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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
  •  
Qt is a trademark of The Qt Company.