Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt4 -i want serial communication
QtWS25 Last Chance

Qt4 -i want serial communication

Scheduled Pinned Locked Moved General and Desktop
serial portserial
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForestPoem
    wrote on 6 Oct 2015, 07:19 last edited by ForestPoem 10 Jun 2015, 07:19
    #1

    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!");
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 6 Oct 2015, 08:16 last edited by kuzulis 10 Jun 2015, 08:18
      #2

      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

      1 Reply Last reply
      0

      2/2

      6 Oct 2015, 08:16

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved