[vlmc-devel] [PATCH 2/3] Fix QTimer running with its interval of 0

Hugo Beauzée-Luyssen hugo at beauzee.fr
Mon Mar 7 13:36:18 CET 2016


On 03/07/2016 12:43 PM, Yikai Lu wrote:
> By letting SettingValue "setLimits" and making it Clamped, we avoid it being 0.
>
> Also, have QTimer run with the interval saved as SettingValue, not just start()
> ---
>   src/Project/Project.cpp | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
> index 3800e51..c37a0ae 100644
> --- a/src/Project/Project.cpp
> +++ b/src/Project/Project.cpp
> @@ -60,7 +60,8 @@ Project::Project( Settings* settings )
>       SettingValue    *automaticBackupInterval = settings->createVar( SettingValue::Int, "vlmc/AutomaticBackupInterval", 5,
>                                       QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save interval" ),
>                                       QT_TRANSLATE_NOOP( "PreferenceWidget", "This is the interval that VLMC will wait "
> -                                                       "between two automatic save" ), SettingValue::Nothing );
> +                                                       "between two automatic save" ), SettingValue::Clamped );
> +    automaticBackupInterval->setLimits(1, QVariant(QVariant::Invalid));
>

That is definitely the correct way!

>       connect( m_timer, SIGNAL( timeout() ), this, SLOT(autoSaveRequired() ) );
>       connect( this, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
> @@ -70,7 +71,7 @@ Project::Project( Settings* settings )
>       connect( automaticBackupInterval, SIGNAL( changed( QVariant ) ), this,
>                SLOT( autoSaveIntervalChanged( QVariant ) ) );
>
> -    m_timer->start();
> +    m_timer->start( automaticBackupInterval->get().toInt() * 1000 * 60 );

This is too early to do, since the settings haven't been restored yet, 
you'll only get the default value. Moreover, we don't want to start the 
timer if "AutomaticBackup" is set to false

>   }
>
>   Project::~Project()
>

Regards,


More information about the Vlmc-devel mailing list