C_and_CPP 板


LINE

开发平台(Platform): (Ex: Win10, Linux, ...) win11 编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出) vs2022 额外使用到的函数库(Library Used): (Ex: OpenGL, ...) Qt、opencv、libtiff 问题(Question): 我在vs中使用Qt分别建立一个QAction和QSlider,该action(open_file)用来开启tiff-s tack档,而QSlider则是控制显示图片的亮度。 但我在执行程式时发现slider在滑动时,connect的变数并没有真正执行与image的变化 想请问是否有其他写法能顺利执行 喂入的资料(Input): 预期的正确结果(Expected Output): QSlider *myslider可以在cv::imshow更新image时,能及时对next_image做操作 (ex: Mat image*test_brightness) // test_brightness与QSlider连结 错误结果(Wrong Output): 程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档) // qt: test_show.cpp test_show::test_show(QWidget *parent) :QMainWindow(parent) ,ui(new Ui::testshowclass) { connect(open_file,&QAction::triggered,this,&open_and_show:open) } //............... // 从QAction打开文件(16bit *tiff)到imshow都可以顺利执行 // 实作libtiff和cv::imshow的class void open_and_show::open(){ QString Filename = QFileDialog::getopenfilename(this,tr("open"),tr("C:\\)); std::string filename = Filename.toStdString(); const char *mypath = filename.c_str(); TIFF *tif = tiffopen(mypath,"r"); TIFFGetField(tif,TIFFTAG_IMAGELENGTH,&height); TIFFGetFiled(tif,TIFFTAG_IMAGEWIDTH, &width ); int ntotalframe = TIFFNumberOfDirectories(tif); uint32_t *slicetif = new uint32_t[width*height]; for(int z=0;z< ntotalframe; ++z){ cv::Mat img(height,width,CV_32FC1,cv::Scalar:all(0)); TIFFReadRGBAImageOriented(tif,width,height,slicetif,ORIENTATION_TOPLEFT); int ss = 0; for (int i=0; i<height;i++){ for (int j=0; j<width ;j++){ img.at<float> = TIFFGetR(sliceTif[ss]); s++; } } TIFFReadDirectory(tif); int test_brightness = 1; cv::normalize(img,img,0,65535,cv::NORM_MINMAX,CV_16UC1); cv::namewindow("hi",cv::WINDOE_GUI_EXPANDED); cv::imshow("hi",img*test_brightness); cv::waitkey(10); } } //............... // 当我想透过QSlider和connect,对img进行操作时却没反应 // Qt test_show.cpp test_show::test_show(QWidget *parent) :QMainWindow(parent),ui(new UI::testshowclass);{ ...... open_and_show *show_class; connect(myslider,SIGNAL(valueChanged(int)),this,SLOT(&test_show:: change_brigh )); ...... } void test_show::change_brigh(){ int bri_val = myslider ->value(); show_class.set_brigh(bri_val); } //.............. void open_and_show::set_brigh(int brightness) { if (test_brightness != brightness){ test_brightness = brightness; } } 补充说明(Supplement): test_show是主要的widget open_and_show则是另个实作的class --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.175.4 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1668067911.A.6FF.html ※ 编辑: Vvvahc (140.112.175.4 台湾), 11/10/2022 16:15:59
1F:→ john790710: 你connect的this(test_show)没有那个method吧11/10 16:36
2F:→ john790710: 看错,是下面不行?change_brigh不要用SLOT包起来试试11/10 16:46
※ 编辑: Vvvahc (140.112.175.4 台湾), 11/10/2022 16:47:12
3F:→ Vvvahc: 我不确定有没有影响,不过我把connect里的 & show_class 11/10 16:49
4F:→ Vvvahc: 改回this仍是一样… 11/10 16:49
5F:→ Vvvahc: 回j大,那个位置不是得用SLOT包吗? 11/10 16:54
6F:→ Vvvahc: 因为前面有single 11/10 16:54
7F:→ Vvvahc: *SIGNAL 11/10 16:56
8F:→ john790710: 你用&就不要用SLOT() 11/10 17:14
9F:→ john790710: https://wiki.qt.io/New_Signal_Slot_Syntax 11/10 17:16
10F:→ Vvvahc: 将Slot去掉也是没变化 11/10 17:45
11F:→ Vvvahc: 我在想是不是得在imshow前连结test_brightness和connect S 11/10 17:45
12F:→ Vvvahc: lot相关的指标 11/10 17:45
13F:→ Vvvahc: 不过我在这都一直收到报错 _ 11/10 17:46
14F:→ Vvvahc: 更: 我後来加指标int *a去存取SLOT的结果 11/10 18:05
15F:→ Vvvahc: 经过if判断,再将Mat img* (*a)便解决了 11/10 18:05
16F:→ Vvvahc: 谢谢j大 11/10 18:05
17F:→ wulouise: Qt5可以不用macro了吧 尽量照范例的用 11/10 23:22
18F:→ wulouise: SIGNAL SLOT runtime很容易就错过那个error msg..Y 11/10 23:23
19F:推 lc85301: 可以在 change_brigh 里面加个 breakpoint 看函式有没有 11/13 11:15
20F:推 lc85301: 喔已经解了XD 11/13 11:15
21F:→ qoorocker: connect 尽量用新语法吧 compile time就知道有没有成功 11/13 21:58







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BabyMother站内搜寻

TOP