link7
31st May 2009, 21:56
Hi all,
I have a problem with QTimer, all I want is to execute a piece of code within a loop each 2 seconds, but nothing happens, here is what I tried:
void Monitor::mark()
{
QTextCursor cursor(textEdit->document());
colorFormat.setForeground(Qt::red);
cursor.setPosition(j);
if (cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 3))
cursor.mergeCharFormat(colorFormat);
}
void Monitor::quickSearch(const char *x, int m, const char *y, int n, QTextEdit *textEdit) {
this->textEdit = textEdit;
j = 0;
int k = 0;
while (j <= n - m) {
if (memcmp(x, y + j, m) == 0)
{
//mark();
QTimer::singleShot(2000, this, SLOT(mark()));
}
j += qsBc[y[j + m]];
}
}
The method mark() works just fine, when I call him without Qtimer, but I want to have a 2secs pause before doing that.
Tried to search forums, but no results.
Using QT4.5, PCLinuxOS
Please help me, I am out of time
I have a problem with QTimer, all I want is to execute a piece of code within a loop each 2 seconds, but nothing happens, here is what I tried:
void Monitor::mark()
{
QTextCursor cursor(textEdit->document());
colorFormat.setForeground(Qt::red);
cursor.setPosition(j);
if (cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 3))
cursor.mergeCharFormat(colorFormat);
}
void Monitor::quickSearch(const char *x, int m, const char *y, int n, QTextEdit *textEdit) {
this->textEdit = textEdit;
j = 0;
int k = 0;
while (j <= n - m) {
if (memcmp(x, y + j, m) == 0)
{
//mark();
QTimer::singleShot(2000, this, SLOT(mark()));
}
j += qsBc[y[j + m]];
}
}
The method mark() works just fine, when I call him without Qtimer, but I want to have a 2secs pause before doing that.
Tried to search forums, but no results.
Using QT4.5, PCLinuxOS
Please help me, I am out of time