Hi everyone,
i want to make a program with a text field and two check boxes: bold and italics which adjust the font in the text field accordingly.
I made QFont a private member in Stuff.h and initialized it in Stuff.cpp - but there seems to be some problem there. I followed the documentation so i dont understand why theres a problem.
the code and errors are mentioned below

Stuff.h
Qt Code:
  1. #ifndef STUFF_H
  2. #define STUFF_H
  3.  
  4. #include <QWidget>
  5. #include <QFont>
  6.  
  7.  
  8. namespace Ui {
  9. class Stuff;
  10. }
  11.  
  12. class Stuff : public QWidget
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit Stuff(QWidget *parent = 0);
  18. ~Stuff();
  19.  
  20. private slots:
  21. void adjustFont();
  22.  
  23. private:
  24. Ui::Stuff *ui;
  25. QFont *font;// font declared here!
  26. };
  27.  
  28. #endif
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "stuff.h"
  2. #include "ui_stuff.h"
  3. #include <QButtonGroup>
  4. #include <QFont>
  5.  
  6. Stuff::Stuff(QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::Stuff)
  9. {
  10. ui->setupUi(this);
  11. font = new QFont("Times",12);
  12.  
  13.  
  14. QButtonGroup *group = new QButtonGroup(this);
  15. group->addButton(ui->SBoldButton);
  16. group->addButton(ui->SItalicButton);
  17. group->setExclusive(false);
  18.  
  19. ui->SLineEdit->setText("this is a line");
  20. ui->SLineEdit->setFont(font);// /home/ubuntu/QtProjects/Stuff-build-desktop/../Stuff/stuff.cpp:23: error: no matching function for call to ‘QLineEdit::setFont(QFont*&)’
  21.  
  22. connect(group,SIGNAL(buttonClicked(int)),this,SLOT(adjustFont()));
  23. connect(ui->SQuitButton,SIGNAL(clicked()),qApp,SLOT(quit()));
  24. }
  25.  
  26. Stuff::~Stuff()
  27. {
  28. delete ui;
  29. }
  30.  
  31. void Stuff::adjustFont()
  32. {
  33. Qt::CheckState boldState;
  34. Qt::CheckState italicState;
  35.  
  36. boldState=ui->SBoldButton->checkState();
  37. italicState=ui->SBoldButton->checkState();
  38.  
  39. if(boldState==Qt::Checked && italicState!=Qt::Checked)
  40. {
  41. ui->SLineEdit->setFont(font->setBold(true));///home/ubuntu/QtProjects/Stuff-build-desktop/../Stuff/stuff.cpp:44: error: invalid use of void expression
  42. ui->SLineEdit->setFont(font->setItalic(false));//same as above and applies for all similar lines of code below
  43. }
  44.  
  45. else if(boldState!=Qt::Checked && italicState==Qt::Checked)
  46. {
  47. ui->SLineEdit->setFont(font->setBold(false));
  48. ui->SLineEdit->setFont(font->setItalic(true));
  49. }
  50.  
  51. else if(boldState==Qt::Checked && italicState==Qt::Checked)
  52. {
  53. ui->SLineEdit->setFont(font->setBold(true));
  54. ui->SLineEdit->setFont(font->setItalic(true));
  55. }
  56.  
  57. else
  58. {
  59. ui->SLineEdit->setFont(font->setBold(false));
  60. ui->SLineEdit->setFont(font->setItalic(false));
  61. }
  62. }
To copy to clipboard, switch view to plain text mode