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 7844909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:03:04+00:00 2026-06-02T17:03:04+00:00

I have a QTabWidget which contains a QPlainTextEdit. I have managed to add action

  • 0

I have a QTabWidget which contains a QPlainTextEdit. I have managed to add action to the QTabWidget so that whenever a new tab opens, a new QPlainTextEdit is also added in the new tab. See code.

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPlainTextEdit>
#include <QMessageBox>
#include <QAction>
#include <QTextCursor>
#include <iostream>
#include <QKeyEvent>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("Tilde");
    current_tab = 1;
    on_action_New_triggered();
    ui->tabWidget->setTabsClosable(true);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_action_New_triggered()
{
    QString newTab = "Tab " + QString::number(current_tab);
    ui->tabWidget->addTab(new QPlainTextEdit, newTab);
    ui->tabWidget->setCurrentIndex(current_tab - 1);
    current_tab++;
    editor = qobject_cast<QPlainTextEdit *>(ui->tabWidget->currentWidget());
    editor->setFocus();
    /*connect(editor->document(), SIGNAL(cursorPositionChanged(QTextCursor)),
            this, SLOT(on_editor_cursorPositionChanged()));*/
}

void MainWindow::on_actionNew_document_triggered()
{
    on_action_New_triggered();
}

void MainWindow::on_action_Exit_triggered()
{
    QMessageBox msg;
    msg.addButton(QMessageBox::Yes);
    msg.addButton(QMessageBox::No);
    msg.setText("Exit program?");

    int selection = msg.exec();

    if (selection == QMessageBox::Yes)
        qApp->exit(0);
}

// highlight current line
void MainWindow::on_editor_cursorPositionChanged()
{
    QTextEdit::ExtraSelection highlight;
    highlight.cursor = editor->textCursor();
    highlight.format.setProperty(QTextFormat::FullWidthSelection, true);
    highlight.format.setBackground( QColor(240, 246, 217) );

    QList<QTextEdit::ExtraSelection> extras;
    extras << highlight;
    editor->setExtraSelections(extras);
}

The commented code gives compiler error:

QMetaObject::connectSlotsByName: No matching signal for
on_editor_cursorPositionChanged()

I have added the function in the header file.

Header file:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPlainTextEdit>
#include <QTextCursor>

namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_action_New_triggered();
    void on_actionNew_document_triggered();
    void on_action_Exit_triggered();
    void on_editor_cursorPositionChanged();

private:
    Ui::MainWindow *ui;
    QPlainTextEdit *editor;
    qint8 current_tab;
};

#endif // MAINWINDOW_H
  • 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-02T17:03:07+00:00Added an answer on June 2, 2026 at 5:03 pm

    Could it be that your signature for the SLOT is wrong?

    /*connect(editor->document(), SIGNAL(cursorPositionChanged(QTextCursor)),
                this, SLOT(on_editor_cursorPositionChanged()));*/
    

    Should be?

    connect(editor->document(), SIGNAL(cursorPositionChanged(QTextCursor)),
                this, SLOT(on_editor_cursorPositionChanged(QTextCursor)));
    

    Also, the naming convention you are using for that slot might be conflicting here with your manual connection. Qt may be trying to use the connectSlotsByName mechanism on your SLOT by matching the name: on_<member>_<signal>

    In this case, the current signature of that SLOT on_editor_cursorPositionChanged() would match with the QPlainTextEdit editor member. And then you are manually connecting the document to it with the wrong signature. You probably should create another slot that is named more normally docCursorPosChanged(QTextCursor)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QLineEdit inside a widget inside a QTabWidget. Let's say that tab
In my application I have a tab bar. It contains four tabs in which
I have Tab Layout that contains a TextView. I'd like to assign some text
I have a QTabWidget , where each tab has a QPlainTextEdit as its widget.
I have an inactive QMainWindow with a QTabWidget as CentralWidget which holds multiple QPlainTextEdits
Let's consider we have QWidget that contains QTableWidget (only). So we want to resize
I have created a custom tab layout which look like this,I want to make
I have a question that I am implementing a tab bar in my android
I have a data base in which multiple items are there.And also I have
I have made an application which has tabs like in HelloTabActivity, there is also

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.