Qt pixmap實現disabled等狀態,libcurl圖片上傳在window和linux下實現,Openssl::SHA1和QCryptographicHash::Sha1

Qt pixmap實現disabled等狀態

QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;

enum Mode { Normal, Disabled, Active, Selected };
enum State { On, Off };

利用QIcon來實現就行

libcurl圖片上傳在window和linux下實現

libcurl window相關庫文件

l#libcurl
LIBS += -L"curl/lib/curl" -llibcurl
LIBS += -L"curl/lib/curl" -llibcurld
INCLUDEPATH += curl/include
#~libcurl

ibcurl linux相關方法

#ubuntu libcurl
#apt-get install libcurl4-openssl-dev
#https://blog.csdn.net/u011641885/article/details/46900771

#libcurl
CONFIG(debug,debug|release):INCLUDEPATH += /usr/include
CONFIG(release,debug|release):INCLUDEPATH += /usr/local/libcurl/include
LIBS +=-lcurl
#~libcurl

window 下推薦使用postman工具來調試post、get、上傳圖片等

post方法:

    CURL* curl = curl_easy_init();
    if(NULL == curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
        curl_easy_setopt(curl, CURLOPT_POST, 1);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
        curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
        res = curl_easy_perform(curl); // 發送
        curl_easy_cleanup(curl);// 清空
    }

get方法:

    CURL* curl = curl_easy_init();
    if(NULL == curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
        curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
        res = curl_easy_perform(curl); // 發送
        curl_easy_cleanup(curl);// 清空
    }

upload image

    CURL* curl = curl_easy_init();
    if(NULL == curl)
    {
    curl_formadd(&formpost,
                 &lastptr,
                 CURLFORM_COPYNAME, filekey.toStdString().c_str(),
                 CURLFORM_FILE, filepath.toStdString().c_str(),
                 CURLFORM_END);
    curl_easy_setopt(hnd, CURLOPT_URL,  url.toStdString().c_str());
    curl_easy_setopt(hnd, CURLOPT_HTTPPOST, formpost);
    ret = curl_easy_perform(hnd);
    //~

    //free
    curl_easy_cleanup(hnd);
    curl_formfree(formpost);
    }

Openssl::SHA1和QCryptographicHash::Sha1

    QCryptographicHash *hash = new QCryptographicHash(QCryptographicHash::Sha1);
    hash->addData(prepare_sign);
    sigret = hash->result().toHex().data();

    QByteArray sigret;
    sigret.resize(20);//SHA1:20,SHA256:32
    SHA1((unsigned char*)prepare_sign.data(), prepare_sign.length(), (unsigned char*)sigret.data());
    sigret = sigret.toHex().toLower();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章