Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:29:09+00:00 2026-06-05T09:29:09+00:00

I derived a class from QTextEdit and use it as a logbook. I equipped

  • 0

I derived a class from QTextEdit and use it as a “logbook”. I equipped it with a slot to receive log-messages.

class CLogbook : public QTextEdit
{
   Q_OBJECT;
    public:
    void log(QString msg) {append(msg)};

    public slots:
    void recvLogSignal(const QString message)
    {    
         append("hallo");
         std::cout << "signal received.\n";    
         log(message);
    }

};

another class then emits a signal like this:

// in the header
signals:
    void logMessage(const QString);

// in the implementation
    emit logMessage("qt is cute");
    std::cout << "if you can read this the logMessage was emitted\n";

and also i connect the signal to the slot

connect(tableeditor, SIGNAL(logMessage(const QString)), logbook, SLOT(recvLogSignal(const QString)));

However the message is never shown in the “logbook”. What am i missing here?

SOLVED: The connect method was called after emitting the signal 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:29:11+00:00Added an answer on June 5, 2026 at 9:29 am

    It is hard to see exactly what is wrong with your implementation without a full example. Sometimes signals or slots will fail if an object goes out of scope if it isn’t initialized on the heap.

    Another way that it could fail is if your QApplication hasn’t reached the exec() call.

    I haven’t experimented with using const in signal and slot calls, and I haven’t seen it in any examples before, so that could be causing the problem; but it seems to work fine in the example below.

    Working Example With a Derived Class of QTextEdit

    Screenshot of example

    Here is a simple example I put together that does some basic logging with a push button and a line edit.

    Here is the header:

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QtGui/QWidget>
    //#include <QTextEdit>
    #include "clogbook.h"
    #include <QLineEdit>
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = 0);
        ~Widget() {}
    public slots:
        void on_pushButton();
        void on_lineEditReturn();
    private:
        CLogBook * text_edit_log;
        QLineEdit * line_edit;
    };
    
    #endif // WIDGET_H
    

    Here is the source:

    #include "widget.h"
    
    #include <QBoxLayout>
    #include <QPushButton>
    #include <QTimer>
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        QBoxLayout * box_layout = new QBoxLayout(QBoxLayout::TopToBottom);
    
        text_edit_log = new CLogBook;
        line_edit = new QLineEdit("Type Here and press Enter.");
        QPushButton * push_button = new QPushButton("Click to Add To Log");
        text_edit_log->setText("My Log Book");
        box_layout->addWidget(text_edit_log);
        box_layout->addWidget(line_edit);
        box_layout->addWidget(push_button);
    
        this->setLayout(box_layout);
    
        QObject::connect(push_button, SIGNAL(clicked()), this, SLOT(on_pushButton()));
        QObject::connect(line_edit, SIGNAL(returnPressed()), this, SLOT(on_lineEditReturn()));
    }
    
    void Widget::on_pushButton()
    {
    //    text_edit_log->append("Push Button Logging Test");
        text_edit_log->recvLogSignal("Push button test.");
    }
    
    void Widget::on_lineEditReturn()
    {
    //    text_edit_log->append(line_edit->text());
        text_edit_log->recvLogSignal(QString("LineEdit: ") + line_edit->text() );
        line_edit->clear();
    }
    

    And here is the main:

    #include <QtGui/QApplication>
    #include "widget.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
    
        return a.exec();
    }
    

    And here is the CLogBook class:

    #ifndef CLOGBOOK_H
    #define CLOGBOOK_H
    
    #include <QTextEdit>
    #include <iostream>
    
    class CLogBook : public QTextEdit
    {
        Q_OBJECT
    public:
        explicit CLogBook(QWidget *parent = 0) : QTextEdit(parent) { }
        void log (QString msg) { append(msg); }
    
    public slots:
        void recvLogSignal(const QString message)
        {
            append("hallo");
            std::cout << "signal received.\n" << std::endl;
            log(message);
        }
    
    };
    
    #endif // CLOGBOOK_H
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I derived a class from CListCtrl called CListCtrlCustomDraw, and use NM_CUSTOMDRAW handler to draw
I use a class derived from HwndHost to host a Win32 window. It is
I derived a class from MembershipProvider in System.Web.Security with the following definition: public class
I have a C# class derived from a generic list public class CostCodes :
My derived class from QGraphicsItem returns a bounding rect of Rect1. QRectF BaseControl::boundingRect() const
I have a derived derived class from an abstract class. The code is below.
I understand overriding a method/function redefines its implementation in the derived class from its
I have a class derived from ItemsControl in which I implement my own selection-algorithm
I have a class derived from CTreeCtrl . In OnCreate() I replace the default
I have a class derived from Dictionary. I need this class to simulate a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.