ubuntu QT Creator Fatal IO error 2 (没有那个文件或目录) on X server :0
這幾天,碰到一個很奇怪的問題,用QT Creator 編寫的程序,在Windows上運(yùn)行良好;移植到MAC上,也測試運(yùn)行沒有問題。現(xiàn)在計(jì)劃把程序移植到Ubuntu上。
移植完成之后,編譯沒有問題(在移植到MAC上時已經(jīng)把Windows與類Unix的語法不兼容的問題全解決了),然后運(yùn)行程序,發(fā)現(xiàn)程序崩潰,并提示如下錯誤:
(程序名:88351): Gdk-WARNING ** 程序名: Fatal IO error 2 (沒有那個文件或目錄) on X server :0.查相關(guān)資料,有這樣的資料:
1)http://m.bubuko.com/infodetail-701169.html
2)https://blog.csdn.net/weixin_30883271/article/details/94776498
3)https://www.cnblogs.com/tibetanmastiff/p/4368755.html
其中博客1和博客3是同一個。這幾個技術(shù)博客大致一個意思,就是圖片資源被多線程搶占了,導(dǎo)致資源不可用。
我自己也試圖調(diào)用Ubuntu上調(diào)用GTK線程的方法,但我發(fā)現(xiàn)方法不起作用。因?yàn)?#xff0c;我自己的程序是,就這部分運(yùn)行的,屬于單獨(dú)調(diào)用的部分,顯然不是多線程的問題。
但這幾篇博客有一個提醒,或者啟示,就是問題為資源被占用了。
我繼續(xù)調(diào)試,想起一個方法:如果程序出問題,把出問題的地方注掉,看程序是否能運(yùn)行。
經(jīng)過多次注釋,發(fā)現(xiàn)當(dāng)文件中存在這圖形框設(shè)置ICon的時候,程序就會出問題。
我自己提供了一個簡單的Demo:
//DLGTITLE, STRINFO 和 LOGOPATH為外部信息QMessageBox box(QMessageBox::Information, DLGTITLE, STRINFO);box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);box.setButtonText(QMessageBox::Yes, QString("是"));box.setButtonText(QMessageBox::No, QString("否"));QString qstrFileName = LOGOPATH;QIcon qIcon(qstrFileName);box.setWindowIcon(qIcon); //當(dāng)設(shè)置Icon的時候,必然會發(fā)生上面問題。box.exec();發(fā)現(xiàn)當(dāng)程序setWindowIcon存在的時候,必然發(fā)生這個問題;把這句話注掉,程序運(yùn)行正常。
于是查詢更多的資料,有關(guān)Ubuntu設(shè)置Icon的。
查到資料如下:
1)https://forum.qt.io/topic/102167/how-to-add-qt-application-icon-in-ubuntu/4
2)https://doc.qt.io/qt-5/appicon.html#setting-the-application-icon-on-common-linux-desktops
原話摘抄如下:
“In this section we briefly describe the issues involved in providing icons for applications for two common Linux desktop environments:?KDE?and?GNOME. The core technology used to describe application icons is the same for both desktops, and may also apply to others, but there are details which are specific to each. The main source of information on the standards used by these Linux desktops is?freedesktop.org. For information on other Linux desktops please refer to the documentation for the desktops you are interested in."
"If you are developing exclusively for GNOME, you may wish to use the standard set of?GNU Build Tools, also described in the relevant section of the?GTK+/Gnome Application Development book. This ensures that your icons are installed in the appropriate locations for GNOME."
大致意思是,Linux圖形化顯示用了兩種策略KDE和GNONE,分別執(zhí)行了不同標(biāo)準(zhǔn)。而顯然,Gdk-WARNING屬于GNOME;也就是GNOME對設(shè)置ICON是有一定限制的。
我自己繼續(xù)查找了資料,大致給出的結(jié)論是:在Ubuntu上和Windows上,資源路徑的尋找方式是不同的。
我修改了下資源路徑,不再用Ubuntu默認(rèn)的方法:獲得路徑法,而采用URL方法,而不是Path方法,發(fā)現(xiàn)不再出現(xiàn)這個問題。
我發(fā)現(xiàn)使用URL方法成功了,但是QT中的ICON沒有成功顯示。我發(fā)現(xiàn),在Ubuntu上,圖標(biāo)是不再是在左邊,于是,我想了個方法,先把所有有關(guān)ICON的方法注掉,程序運(yùn)行正確。
如何設(shè)置正確的ICON,會在以后繼續(xù)尋找方法。
——————————————————————————————————————————————分割線
經(jīng)過測試,在Ubuntu上,setWindowIcon僅僅為設(shè)置程序的Icon(即在啟動器一欄上的圖標(biāo)),而不能如Windows一樣,是既設(shè)置程序的圖片,又設(shè)置程序左上角的Icon。
?
總結(jié)
以上是生活随笔為你收集整理的ubuntu QT Creator Fatal IO error 2 (没有那个文件或目录) on X server :0的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机课睡觉检讨书,上课睡觉检讨书范文三
- 下一篇: js斐波那契数列求和