Results 1 to 3 of 3

Thread: How to get const char[] from several QLineEdit and combine them

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default How to get const char[] from several QLineEdit and combine them

    Hi,

    First of all, I'm not quite experienced about C++/Qt. There is a thread about getting const char* from QLineEdit but it doesn't fit my project exactly. Anyway, if I wrote something that doesn't make sense. Please, forgive me.

    I'm working on a serial port application using QextSerialPort. I have a device and I want it to be controlled by serial port Qt Gui Application in Win7. In my Gui, there is a setting dialog called "parameter settings" and in this parameter settings there are some QLineEdits and couple pushbuttons to read/write actions. I should send data to the device as ascii character array.

    Here is my setting dialog screenshot:
    parameters.png

    Before I got started my project, I sent some commands from a sample gui which is working on only WinXP and probed the serial lines.

    According to this values ( SC=0, P=9.5, I=88, D=58, A1=560, A2=30, A2S=5, A3=10), when I clicked the write button, observed data with specific time interval as shown below.

    SC -> 010610040000E5
    P -> 01061006005F84
    I -> 01061008005889
    D -> 0106100A003AA5
    A1 -> 0106100C0230AB
    A2&A2S -> 0106100E1E05B8
    A3 -> 01061010000ACF

    As you can see from bold characters, hexadecimal representation of decimal parameters are placed in array. Last two char of the array increment 1, when the parameters decrement 1 and vice versa.

    Here is my sample code that sends the const char array to the device.

    Qt Code:
    1. const char test_param_data[] = "010310040008E0";
    2. if (!port->isOpen()) {
    3. port->open(QIODevice::ReadWrite);
    4. port->write(test_param_data, sizeof(test_param_data));
    5. ui->lineEdit_9->setText("Test OK");
    6. }
    7. else
    8. {
    9. port->write(test_param_data, sizeof(test_param_data));
    10. ui->lineEdit_9->setText("Test Done");
    11. }
    To copy to clipboard, switch view to plain text mode 

    I hope I make myself clear about my problem. Briefly, how can I get these parameters as in specific order and converted to const char?

    Thanks in advance.

    Anil.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to get const char[] from several QLineEdit and combine them

    Quote Originally Posted by kirkil View Post
    I hope I make myself clear about my problem.
    No, I don't think you have.

    You have some arbitrary strings people might type in some QLineEdits
    You have some other arbitrary bytes that you display as hexadecimal strings that are related in some unexplained way to the values a user might type. It seems that, for the integer values anyway, that the second/third last byte is the value. I guess the fixed point value is expressed as an integer number of tenths. Ultimately we really have no idea what the other bytes are.
    You have a sample that writes a fixed (hexadecimal) string to the serial port that does not relate to any of the other hexadecimal values you have displayed.

    Briefly, how can I get these parameters as in specific order and converted to const char?
    You get them in a particular order by accessing them in a particular order.
    You can convert/access a QString as a plain C-string in several of ways, but it strong depends on exactly what you are expecting to send.

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get const char[] from several QLineEdit and combine them

    Quote Originally Posted by ChrisW67 View Post
    Ultimately we really have no idea what the other bytes are.

    Yes, I forgot to mention about the other bytes, sorry for that.

    SC -> 010610040000E5
    P -> 01061006005F84
    I -> 01061008005889
    D -> 0106100A003AA5
    A1 -> 0106100C0230AB
    A2&A2S -> 0106100E1E05B8
    A3 -> 01061010000ACF

    When I change the parameters, 010610 is remaining same. So, I always have them at the beginning of data. The 4 bytes that come after 010610 represent the order of data which will be sent. I think 04 indicates that string is the first to be sent and 10 indicates that string is the last to be sent. (04 06 08 0A 0C 0E 10). Next 8 bytes are related to values that user might type. I think the pattern is like that. For example, for SC value 01+06+10+04+0000+E5 = 100, for P value 01+06+10+06+005F+84 = 100 so on. Sum of the values of each data equals to hexadecimal 100. So , the last 4 bytes depend on the other bytes.

    Quote Originally Posted by ChrisW67 View Post
    You have a sample that writes a fixed (hexadecimal) string to the serial port that does not relate to any of the other hexadecimal values you have displayed.
    Indeed, that fixed string doesn't relate to to any of the values i have displayed. I just wrote it for an example to show how I send the data. You might consider another data instead of that data.

Similar Threads

  1. Getting const char * from QLineEdit
    By squidge in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 09:28
  2. Connect with const char*
    By grazyna in forum Qt Programming
    Replies: 7
    Last Post: 14th August 2009, 18:13
  3. char to const char* with atof
    By mickey in forum General Programming
    Replies: 5
    Last Post: 29th February 2008, 04:10
  4. qt_metacast(const char*)
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 3rd September 2007, 07:03
  5. QString to const char
    By TheRonin in forum Newbie
    Replies: 2
    Last Post: 12th February 2007, 14:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.