Important: Please read the Qt Code of Conduct -

Calling update frequently

  • hi all,

    i am newbie to qt so please bear with me if solution is very obvious. My question is that i have a class MapGenerator which is calling a function of my Qt class Mainwindow and updates the value of a variable and later this variable is used in paintevent method. i.e
    @class MapGenerator{
    void somefunction()
    {Mainwindow w:

    Now in class Mainwindow i have

    @class MainWindow{
    void updatemap(int data)
    save data;

    void paintEvent(){
    using that data doing painting

    Now the problem is that when first time updatemap is called and paint event gets that data and paint but for the second call or frequent call i dont know how to handle recalling paintevent . i tried update() in MainWindow::updateMap() after saving data but it yielded me segmentation fault.
    (p.s class MapGenerator is on other thread so updatemap is being called from other thread not the main thread so update() shouldnt work from there but signals/slot also gives the same error)

    i am using ubuntu 10.04 with qt 4. The code provided here is just psuedo code for keeping things simple.

  • How about timer which will check changing of value and signal update if value is changed.

  • Emitting a signal in updateMap that is connected to MainWindow::update() should work, even when the signal is emitted from a seperate thread. The slot should then be executed in the receiver's thread.

Log in to reply