Qt4 -i want serial communication



  • my Qt4.8 fedora linux Qtcreator

    Mysource error QSocketNotifier: Invalid socket specifieds.

    Why does this error appear?

    And the one known example would be appreciated .


    #include "interface.h"

    #include <QString>

    Interface::Interface(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f)
    {
    setupUi(this); // 메인화면 셋팅

    QObject::connect(btnSend, SIGNAL(clicked()), SLOT(onBtnSendClick())); // 메뉴 버튼과 메뉴 화면 연결
    

    struct termios newtio;

    fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK); // (2) com1을 open

    memset( &newtio, 0, sizeof(newtio) );
    newtio.c_cflag = B115200; // (3) 통신 속도 115200
    newtio.c_cflag |= CS8; // (4) 데이터 비트가 8bit
    newtio.c_cflag |= CLOCAL | CREAD; // (5) 쓰기는 기본, 읽기도 가능하게
    newtio.c_iflag = IGNPAR; // (6) 패리티 오류 무시
    newtio.c_oflag = 0;
    newtio.c_lflag = 0;
    newtio.c_cc[VTIME] = 0;
    newtio.c_cc[VMIN] = 1;

    tcflush (fd, TCIFLUSH );
    tcsetattr(fd, TCSANOW, &newtio );

    notRsRead = new QSocketNotifier( fd, QSocketNotifier::Read, this);
    }

    void Interface::onBtnSendClick()
    {
    QString userInput( edtInput->text());

    const char* text2 = userInput.toAscii();
    
    if( 0 > write( fd, text2, userInput.length()) )
        QMessageBox::information(this, "rs232", "Sending Error!");


  • Use QtSerialPort instead (branch qt4-dev): http://code.qt.io/cgit/qt/qtserialport.git/?h=qt4-dev
    Wiki: https://wiki.qt.io/Qt_Serial_Port

    PS: Also you can install QtSerialPort from the Fedora's repo


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.