顯示具有 QT 標籤的文章。 顯示所有文章
顯示具有 QT 標籤的文章。 顯示所有文章

2017年12月10日 星期日

[Python] Eric IDE For Python On Ubuntu16.04

  • 安装QT5
    Ref : http://smlie-blog.blogspot.tw/2017/11/qtqt5ubuntu1604.html
  • 安装相關套
    • pip3
      #apt-get install python3-pip
      #pip3 install --upgrade pip
    • PyQt5
      #pip3 install PyQt5
    • Mercurial
      #apt-get install mercurial
    • QScintilla
      #pip3 install QScintilla
    • Eric
      #hg clone hg clone https://die-offenbachs.homelinux.org/hg/eric
      #cd eric
      #python3 install.py
Reference :
[1] https://eric-ide.python-projects.org/index.html
[2]Install Eric 6 for Python (Windows/Ubuntu)

2017年11月12日 星期日

[QT]安装QT5至Ubuntu16.04


  • Download
    #wget http://download.qt.io/official_releases/qt/5.7/5.7.0/qt-opensource-linux-x64-5.7.0.run
  • Install
    #apt-get install build-essential
    #apt-get install libfontconfig1
    #apt-get install mesa-common-dev #for opengl
    #apt-get install libglu1-mesa-dev
    #apt-get install fcitx-frontend-qt5
    #cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so /tmp
    #chmod 777 qt-opensource-linux-x64-5.7.0.run
    #./qt-opensource-linux-x64-5.7.0.run #照步骤完成
    #mv /tmp/libfcitxplatforminputcontextplugin.so /opt/Qt5.7.1/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts #设定sogou输入
Reference
[1] https://wiki.qt.io/Install_Qt_5_on_Ubuntu

2017年8月23日 星期三

[QT] 使用QT設定 TCP/IP KeepAlive

在TCP/IP的機制下所建立的連線,如果Server/Client雙方都沒有要求執行結束的 Four-way handshake,則在TCP/IP機制下,雙方會認為對方一直連線中,直到Timeout结束後才會斷線。通常Timeout時間依據不同的作業系統而有些差異,但時間單位都是小時等級的,故就會發生如對方機器電源已斷電,但程式還是一直保持在E「STABLISHED」的狀態。


如果要解決這個問題,就可以使用TCP/IP 的KeepAlive機制,顧名思義,就是雙方定時回報還活著。範例如下,
QTcpSocket *_socket = new QTcpSocket(this);
if ( _socket != NULL ) {
    _socket->connectToHost(_address, _port);
    if ( _socket->waitForConnected(1000)) {
        int fd = _socket->socketDescriptor(); //一定要連線成功才可取得 descriptor
        int enableKeepAlive = 1;
        setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &enableKeepAlive, sizeof(enableKeepAlive));
        int maxIdle = 10;/* seconds */
        setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &maxIdle, sizeof(maxIdle));
        int count = 3;//send up to 3 keepalive packets out, then disconnect if no response
        setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &count, sizeof(count));
        int interval = 2;//send a keepalive packet out every 2 seconds (after the 5 second idle period)
        setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
    }
}

而Linux的系统預設值如下,(注意:修改該參數則會影響到所以的Socket設定)
#cat /proc/sys/net/ipv4/tcp_keepalive_time 7200
#cat /proc/sys/net/ipv4/tcp_keepalive_intvl 75
#cat /proc/sys/net/ipv4/tcp_keepalive_probes 9

Reference : 
[1] QTcpSocket狀態總是連接,甚至連接到乙太網

2017年8月17日 星期四

[Qt] Qml与Qml間資料互傳

main.qml
Window{
    id : window
    Text {
        id : display

    }
    Component.onCompleted: {
        Qt.display = display; // Qt.[ObjectName] = [ObjectId]
    }
}

page.qml
Checkbox {
    onClicked : {
        Qt.display.text = "Just Do it" ; // Qt.[ObjectName] = [Operate]
    }
}

2017年8月14日 星期一

[QT] qt.qpa.input: X-less xkbcommon not available, not performing key mapping

錯誤:
qt.qpa.input: X-less xkbcommon not available, not performing key mapping

解法:
環境變數加入
export QT_QPA_EGLFS_NO_LIBINPUT=1


Reference :
[1] https://github.com/carlonluca/pot/issues/54

2016年10月17日 星期一

[QT] QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

Error Message

QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

會出現上述問題是因為重複使用了DB Driver,只要在開啟DB時給于名稱


方法一:使用預設名稱
QSqlDatabase datebase;    
if(QSqlDatabase::contains("qt_sql_default_connection"))
    datebase = QSqlDatabase::database("qt_sql_default_connection");
else
    datebase = QSqlDatabase::addDatabase("QSQLITE");

QSqlQuery query; //不指定,則使用defaults


方法二:自訂名稱
QSqlDatabase datebase;    
if(QSqlDatabase::contains("QSQLITE"))
     datebase = QSqlDatabase::database("QSQLITE");
else
     datebase = QSqlDatabase::addDatabase("QSQLITE", "QSQLITE");

QSqlQuery *query = new QSqlQuery(database); //不指定,則使用defaults


2016年9月29日 星期四

2016年9月18日 星期日

[QT] 型態轉換


  • const char * to QString
    const char *charstr = "charstring";
    QString qstring = QString(QLatin1String(charstr));

  • Integer to QString
    int num = 10;
    QString qstring = QString::number(num,10);

  • QString to const char *
    QString message = "test";
    char * c_message = message.toLatin1().data();

  • QByteArray to unsigned char *
    QByteArray message;
    message.resize(5);
    message[0] = 0xFF;
    message[1] = 0xFE;
    unsigned char * c_message = (unsigned char *)message.data();