标题:X11下用QT designer编的程序怎么在非X11环境下使用
作者:leaver
日期:2006-05-30 03:44
内容:
请问X11下用QT designer编的程序怎么在非X11环境下使用?
我编的程序在图形界面下可以用但在文字界面下就提示“can not connect to X server”
请问诸位高手该怎么解决?
#1 [chwoozy 05-30 08:53]
必须要进入X环境才能使用,因为Qt库只能运行在X库上的,不能在文字界面下运行
#2 [leaver 05-30 15:18]
那可不可以修改使它在文字界面下调用其他的库?
#3 [jacklee 06-15 18:40]
QT可以在字符界面下的
只要你编的就是CUI的程序,没有调用GUI的类
在QApplication里设参数就可以了
QApplication::QApplication ( int & argc, char ** argv, bool GUIenabled )
Constructs an application object with argc command line arguments in argv. If GUIenabled is true, a GUI application is constructed, otherwise a non-GUI (console) application is created.
Set GUIenabled to false for programs without a graphical user interface that should be able to run without a window system.
On X11, the window system is initialized if GUIenabled is true. If GUIenabled is false, the application does not connect to the X server. On Windows and Macintosh, currently the window system is always initialized, regardless of the value of GUIenabled. This may change in future versions of Qt.
The following example shows how to create an application that uses a graphical interface when available.
int main(int argc, char **argv)
{
#ifdef Q_WS_X11
bool useGUI = getenv("DISPLAY") != 0;
#else
bool useGUI = true;
#endif
QApplication app(argc, argv, useGUI);
if (useGUI) {
// start GUI version
...
} else {
// start non-GUI version
...
}
return app.exec();
}
#4 [chwoozy 06-30 13:04]
不好意思献丑了