hi,
That example is good but if i use widgets(using the documentation example) i get the same error.Is the problem because i try to access widgets from different thread.so how we can make make a responsive Gui where data runs in background.I have attached the code that i tried.
void colorizeButton1()
{
int index = 0;
while(true)
{
if(index%2 == 0)
{
button1
->setPalette
(*(new QPalette(Qt
::green)));
}
else
{
button1
->setPalette
(*(new QPalette(Qt
::yellow)));
}
index++;
}
}
int main(int argc, char **argv)
{
layout->addWidget(button1);
window->setCentralWidget(central);
QFuture<void> f1 = QtConcurrent::run(colorizeButton1);
f1.waitForFinished();
window->show();
app.exec();
}
void colorizeButton1()
{
int index = 0;
while(true)
{
if(index%2 == 0)
{
button1->setPalette(*(new QPalette(Qt::green)));
}
else
{
button1->setPalette(*(new QPalette(Qt::yellow)));
}
index++;
QThread::sleep(1);
}
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMainWindow *window = new QMainWindow();
QWidget *central = new QWidget(window);
button1 = new QPushButton(central);
QHBoxLayout* layout = new QHBoxLayout(centralWidget);
layout->addWidget(button1);
window->setCentralWidget(central);
QFuture<void> f1 = QtConcurrent::run(colorizeButton1);
f1.waitForFinished();
window->show();
app.exec();
}
To copy to clipboard, switch view to plain text mode
thanks,
Bookmarks