JaGoLi / ytdl-gui

A simple-to-use, cross-platform graphical interface for youtube-dl.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Recommendation] Modernize the code by using Qt5 signal APIs instead of Qt4's

mhogomchungu opened this issue · comments

Below codes looks strange in a new Qt5 only project

    connect(downloadThread, SIGNAL(started()), this, SLOT(messageDownload()));
    connect(downloadThread, SIGNAL(started()), this, SLOT(setStatusClose()));
    connect(downloadThread, SIGNAL(started()), download_instance, SLOT(download()));
    connect(download_instance, SIGNAL(returnFinished(int)), this, SLOT(setStatusClose()));
    connect(download_instance, SIGNAL(returnFinished(int)), this, SLOT(printResult(int)));

Their Qt5 equivalent is

    connect(downloadThread, &QThread::started,[this](){messageDownload();});
    connect(downloadThread, &QThread::started,[this](){setStatusClose();});
    connect(downloadThread, &QThread::started,[download_instance](){download_instance->download();});

    connect(download_instance, &mainCommand::returnFinished,[this](int){setStatusClose();});
    connect(download_instance, &mainCommand::returnFinished,[this](int s){printResult(s);});

Using lambdas and Qt5 signals may require a some refactoring but i think it will make the code a lot more pleasant to look at from strangers and it greatly improves readability sometimes when slot code is placed in a lambda itself so that its easy to see the code that will execute at a place were the connection is made.

After working on other projects, the refactoring, improvement, and modernization of this one starts. All connect calls have been updated to qt5 in the latest beta commit.