Bonjour,

je suis entrain de coder un éditeur de document basique en Qt où il y a une coloration syntaxique. Pour ça, j'ai suivi l'exemple de Nokia http://harmattan-dev.nokia.com/docs/...ghlighter.html
mais lors de la compilation de mon application il me fait une belle erreur sur la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
highlight = new Highlighter(ui->rawText->document());
voila l'erreur que je n'arrive pas à corriger.
cannot allocate an object of abstract type 'Highlighter'
voila le code
highlighter.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "highlighter.h"
 
Highlighter::Highlighter(QTextDocument *parent)
    : QSyntaxHighlighter(parent)
{
    HighlightingRule rule;
 
    tagFormat.setForeground(Qt::yellow);
    rule.pattern = QRegExp("^<(.*)\\>$");
    rule.format = tagFormat;
    highlightingRules.append(rule);
 
    quoteFormat.setForeground(Qt::darkGreen);
    rule.pattern = QRegExp("\".*\"");
    rule.format = quoteFormat;
    highlightingRules.append(rule);
 
    commentFormat.setFontItalic(true);
    commentFormat.setForeground(Qt::gray);
    rule.pattern = QRegExp("\\<!--.*\\-->");
    rule.format = commentFormat;
    highlightingRules.append(rule);
}
highlighter.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
 
#include <QSyntaxHighlighter>
 
#include <QTextCharFormat>
 
class QTextDocument;
 
class Highlighter : public QSyntaxHighlighter
 {
     Q_OBJECT
 
 public:
     Highlighter(QTextDocument *parent = 0);
 
 protected:
 
 private:
     struct HighlightingRule
     {
         QRegExp pattern;
         QTextCharFormat format;
     };
 
     QVector<HighlightingRule> highlightingRules;
 
     QTextCharFormat tagFormat;
     QTextCharFormat quoteFormat;
     QTextCharFormat commentFormat;
 };
#endif // HIGHLIGHTER_H
mainwindow.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
 
    setupFileMenu();
    setupEditor();
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
void MainWindow::newFile()
{
    ui->rawText->clear();
    ui->finalText->clear();
}
 
void MainWindow::openFile(const QString &path)
{
    QString fileName = path;
 
    if(fileName.isNull())
    {
        fileName = QFileDialog::getOpenFileName(this,
                     tr("Open File"), "", "Web Files (*.html)");
    }
    if(!fileName.isEmpty())
    {
        QFile file(fileName);
        if(file.open(QFile::ReadOnly | QFile::Text))
        {
            ui->rawText->setPlainText(file.readAll());
        }
    }
}
 
void MainWindow::setupEditor()
{
    QFont font;
    font.setFamily("Courier");
    font.setFixedPitch(true);
    font.setPointSize(10);
 
    ui->finalText->setFont(font);
    ui->rawText->setFont(font);
 
    highlight = new Highlighter(ui->rawText->document());
 
}
 
void MainWindow::setupFileMenu()
{
    QObject::connect(ui->openButton, SIGNAL(clicked()), this, SLOT(openFile()));
    QObject::connect(ui->newButton, SIGNAL(clicked()), this, SLOT(newFile()));
}
mainwindow.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QFile>
#include <QFileDialog>
 
#include "highlighter.h"
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
public slots:
    void newFile();
    void openFile(const QString &path = QString());
 
private:
    Ui::MainWindow *ui;
 
    void setupEditor();
    void setupFileMenu();
 
    Highlighter *highlight;
};
 
#endif // MAINWINDOW_H
Merci pour vos réponse