0

I am trying to add rich text editing to my application and I cant seem to get it to work. This is just one example but I cant get it to work. Can anyone please tell me what I am missing?

Here is the code that I have so far... this is in the .h file

private slots:
void newFile();
void open();
bool save();
bool saveAs();
void about();
void documentWasModified();
void bold();

and this is in the .cpp file... also I have #include <QTextEdit>

    void MainWindow::bold()
{
}

along with this down the page a little more

boldAct = new QAction(tr("&Bold"), this);
    boldAct->setCheckable(true);
    boldAct->setShortcut(QKeySequence::Bold);
    boldAct->setStatusTip(tr("Make the text bold"));
    connect(boldAct, SIGNAL(triggered()), this, SLOT(bold()));
NG_
  • 6,895
  • 7
  • 45
  • 67
Zach Starnes
  • 3,108
  • 9
  • 39
  • 63
  • There is a textedit demo with Qt that does exactly this. Why don't you have a look at how it's implemented? – Dan Milburn Nov 02 '12 at 10:03
  • I have tried looking at what you are talking about and I have added all the things I thought were it from the reference document and nothing works. The button can get pressed and everything but the text does not get bolded. – Zach Starnes Nov 02 '12 at 14:57
  • You will need to provide a lot more detail about the implementation of your bold() slot before anyone can help you. – Dan Milburn Nov 02 '12 at 15:12
  • I'm sorry I'm kind of new at this. What I presented is all that I have. All I have is a button to type bold and to make selected text bold. The only thing is is it won't bold. I need to know what I'm missing. I apologize for not knowing what you need – Zach Starnes Nov 02 '12 at 15:17
  • It's sad to say I have even resorted to copy pasting everything I thought I needed and changed the names to match mine but still does not work – Zach Starnes Nov 02 '12 at 15:44
  • So assuming you have created a QTextEdit, all you need to do is, in your bold() slot, call textEdit->setFontWeight(QFont::Bold), and that should work. – Dan Milburn Nov 02 '12 at 16:07
  • WOW! thank you so much I cant believe It was that easy. I appreciate your time and knowledge! – Zach Starnes Nov 02 '12 at 16:43

1 Answers1

0

QAction signal's signature is not correct. It should be

connect(boldAct, SIGNAL(triggered(bool)), this, SLOT(bold()));

or even

connect(boldAct, SIGNAL(triggered(bool)), SLOT(bold()));

Also QObject::connect() returns a boolean value, describing connection success.

QMetaObject::checkConnectArgs() is useful to verify that signal and slot can be connected.

divanov
  • 6,173
  • 3
  • 32
  • 51