CURL download_progress throws SIGSEGV
CURL download_progress throws SIGSEGV
我必须更新download_progress中的进度条值,但是每当我尝试更新myClass的成员函数时,它会一直发送分段的错误 这是我的代码:
class myClass{
int percent;
ProgressBar bar;
public:
int download(const char* url, const char* filename, int enable_progress);
int download_progress(void *p, double dl, double dlnow, double ul, double ulnow);
};
int myClass::download_progress(void *cli, double dl, double dlnow, double ul, double ulnow)
{
double p = (dl / dlnow) * 100;
myClass *mp = (myClass *)cli;
mp->percent = (int)dl;
mp->bar.setVal(p)
return 0;
}
int myClass::download(const char* url, const char* filename)
{
int res = 0;
CURL* handle = curl_easy_init();
if (handle == NULL) {
return -1;
}
FILE* f = fopen(filename, "wb");
if (!f) {
return -1;
}
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, f);
curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, (curl_progress_callback)&myClass::download_progress);
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(handle, CURLOPT_USERAGENT, "InetURL/1.0");
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_perform(handle);
curl_easy_cleanup(handle);
off_t sz = ftello(f);
fclose(f);
if ((sz == 0) || (sz == (off_t)-1)) {
res = -1;
remove(filename);
}
return res;
}
尝试从URL下载文件到文件名,但它一直在投掷sigsegv 为什么我无法在上述代码中更新MyClass的成员... 任何帮助将不胜感激
谢谢
首先您需要做
&myClass::download_progress
进入静态功能,并将其称为:
&download_progress
您没有发送要调用的用户数据。您的下载方法应该是这样:
curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, (curl_progress_callback)&myClass::download_progress);
curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, this);
另外,您的download_progress应该标记为静态:
class myClass{
int percent;
ProgressBar bar;
public:
int download(const char* url, const char* filename, int enable_progress);
static int download_progress(void *p, double dl, double dlnow, double ul, double ulnow);
};
相关文章:
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- std::filesystem::copy throws filesystem_error
- SIGSEGV 使用shared_ptr引用时
- SIGSEGV, 分段错误. 而 printf() 数组索引的值
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- 分段故障 运行C++代码时出现 SIGSEGV
- Qt5 throws std::bad_alloc
- 为什么我的递归代码给出 sigsegv 错误?
- 在使用堆栈为下一个最大数字编写代码时面临 SIGSEGV(分段错误)
- VirtualAllocEx throws ERROR_INVALID_HANDLE
- 在Hackerearth上获取运行时错误(SIGSEGV),无法找出代码中的问题
- 为什么在环路条件中使用'<='而不是'<'会产生分段错误 [SIGSEGV]?
- C++ - 程序接收信号SIGSEGV,分段错误.In msvcrt!memcpy () (C:\Windows\S
- 使用 dlopen 在 Mac 上加载 libjvm.dylib 时发出信号 SIGSEGV
- SIGSEGV通过写入局部变量
- 哪个部分导致"SIGSEGV"错误以及如何修复它?
- 进程过早退出,并发出 SIGSEGV 信号
- 我的代码上的运行时错误 sigsegv
- SIGSEGV 因为基/派生类的继承问题
- CURL download_progress throws SIGSEGV