Results 1 to 14 of 14

Thread: Problem with variable in main.cpp and mainwindow.cpp

  1. #1

    Default Problem with variable in main.cpp and mainwindow.cpp

    Hi.
    I need a help.
    I have a variable int bit2, which is a mainwindow.h.
    In main.cpp I calculate her value, and I want to send this value to mainwindow.cpp. Is this possible?
    I include part of the cod:

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4.  
    5. #include <QMainWindow>
    6. static int bit2;
    7. namespace Ui {
    8. class MainWindow;
    9.  
    10. }
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16.  
    17. public:
    18. explicit MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20. int flag;
    21. void zapisz(int wartosc);
    22.  
    23.  
    24.  
    25. private slots:
    26.  
    27.  
    28. private:
    29. Ui::MainWindow *ui;
    30.  
    31.  
    32. };
    33.  
    34. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    main.cpp
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication a(argc, argv);
    4. MainWindow w;
    5. w.show();
    6. ...
    7. ...
    8. w.zapisz(51);
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. QPixmap pix("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_grn.bmp");
    11. QPixmap pix2("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_red.bmp");
    12.  
    13. ui->label->setPixmap(pix);
    14. ui->label_2->setPixmap(pix);
    15. ui->label_3->setPixmap(pix);
    16. ui->label_4->setPixmap(pix);
    17. flag=0;
    18. int bit;
    19. bit=bit2;//TU JEST BLAD ;/
    20. ...
    21. ...
    22. void MainWindow::zapisz(int wartosc)
    23. {
    24. bit2=wartosc;
    25. }
    To copy to clipboard, switch view to plain text mode 

    When I write in mainwindow.cpp ¨bit=51¨ (value which I want calculate in main.cpp) programm is working. In my opinion bit2 in main.cpp and bit2 in mainwindow.cpp is different variable. Can someone help? There is any way to send value from main.cpp to mainwindow.cpp?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Don't use a global variable for this. Either pass the variable to the constructor of MainWindow or add a method to MainWindow where you can pass the variable as a function argument and store in class member variable, etc.

    Edit: I see now that you did try to add a method to set the value, but instead of declaring bit2 as a static global variable, make it a private member variable of MainWindow, then assign the value passed in your MainWindow::zapisz method.

    Qt Code:
    1. // MainWindow.h
    2. class MainWindow
    3. {
    4. ...
    5. private:
    6. int bit2;
    7. }
    8.  
    9. // MainWindow.cpp
    10. void MainWindow::zapisz(int wartosc)
    11. {
    12. bit2 = wartosc;
    13. }
    To copy to clipboard, switch view to plain text mode 

    Does that not do what you want?
    Last edited by jefftee; 10th July 2015 at 07:40.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    I made in private, like you, but still isn´t work. While I use a method m.zapisz(51), value 51 is in bit2, or m.bit2? Because if in m.bit2, mainwindow.cpp can´t see this value :/

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    As a general note, don't define static variables in header files, as each .cpp file which includes the header will get its own copy of the variable.
    Typically you only declare the variable in header:
    Qt Code:
    1. // header.h
    2. extern int my_var;
    To copy to clipboard, switch view to plain text mode 
    and define it in exactly one .cpp file:
    Qt Code:
    1. // impl.cpp
    2. #include "header.h"
    3.  
    4. int my_var = 0;
    To copy to clipboard, switch view to plain text mode 
    In your case I suggest not using the global variable at all anyway.

  5. #5

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Hi, Iḿ not sure I understand you.
    I should write extern int bit in private section in mainwindow.h?
    And then, where I should write this:

    // impl.cpp
    #include "header.h"

    int my_var = 0;


    impl.cpp is my main.cpp or mainwindow.cpp? and int my_var is my bit?

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    I should write extern int bit in private section in mainwindow.h?
    No no, just do that as @jefftee suggested - remove the static variable completely. Use only member variable in the MainWindow class.
    I mentioned the "extern" keyword as a sidenote, so that you know it for future.

  7. #7

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Ok, i did it how @jefftee show, but still doesn´t work how I want :/ In main.cpp i have w.zapisz(51), so bit should have value 51, but in mainwindow.cpp bit don´t have a value :/

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Are you sure you are reading the variable after your wrote to it?

    Cheers,
    _

  9. #9
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Repost your current code for all of main.cpp, MainWindow.cpp, and MainWindow.h.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  10. #10

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Ok, so this is my code:

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4.  
    5. #include <QMainWindow>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9.  
    10. }
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16.  
    17. public:
    18. explicit MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20. int flag;
    21. void zapisz(int wartosc);
    22.  
    23.  
    24.  
    25. private slots:
    26.  
    27.  
    28. private:
    29. Ui::MainWindow *ui;
    30. int bit;
    31.  
    32. };
    33.  
    34. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 



    main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4.  
    5.  
    6. /* simple CAN application example using can4linux
    7.  *
    8.  * open CAN and test the read(2) call
    9.  * An calling option decides if the CAN device is opened for
    10.  * blocking or nonblocking read.
    11.  * Copyright (c) 2014-2015 H.J.Oertel
    12.  *
    13.  * Option: -H
    14.  * Explaining the 'horch' like Format
    15.  * 7884.098543 10/0x0000000a : bD ( 8
    16.  * 55 02 03 04 05 06 07 aa
    17.  * | | | | | |
    18.  * | | | | | +- data bytes, hex coded
    19.  * | | | | +- length information of CAN frame
    20.  * | | | +- Frame information
    21.  * | | | bD - Base Frame Format, Data Frame
    22.  * | | | eD - Extended Frame Format, Data Frame
    23.  * | | | bR - Base Frame Format, Remote Frame
    24.  * | | | eR - Extended Format, Remote Frame
    25.  * | | +- CAN Frame ID in Hex
    26.  * | +- CAN Frame ID in decimal
    27.  * +--- Time stamp: s.µs
    28.  */
    29. #include <stdio.h>
    30. #include <stdlib.h>
    31. #include <sys/types.h>
    32. #include <sys/stat.h>
    33. #include <sys/time.h>
    34. #include <sys/ioctl.h>
    35. #include <fcntl.h>
    36. #include <unistd.h>
    37. #include <string.h>
    38. #include <time.h>
    39. #include <stdbool.h>
    40. //#include <Python2.7.h>
    41.  
    42.  
    43.  
    44. #ifdef USE_RT_SCHEDULING
    45. # include <sched.h>
    46. # include <sys/mman.h>
    47. #endif
    48.  
    49. # define HAVE_TERMIOS
    50. # include <termios.h>
    51. # include <sys/resource.h>
    52. # include <signal.h>
    53.  
    54. #include <can4linux.h>
    55.  
    56. // #define USER_TERMIOS
    57.  
    58. #define STDDEV "/dev/can0"
    59. #define COMMANDNAME "receive"
    60. #define VERSION "SVN $Revision: 471 $"
    61. #define RXBUFFERSIZE 100
    62.  
    63. #ifndef TRUE
    64. # define TRUE 1
    65. # define FALSE 0
    66. #endif
    67.  
    68.  
    69.  
    70.  
    71. int sleeptime = 1000; /* standard sleep time */
    72. int debug = FALSE;
    73. int baud = -1; /* dont change baud rate */
    74. int blocking = TRUE; /* open() mode */
    75. int buffers = RXBUFFERSIZE;/* open() mode */
    76. int listenmode = FALSE; /* listen only mode */
    77. int selfreception = FALSE; /* selfreception mode */
    78. int settsmode = FALSE; /* Set Time Stamp Format */
    79. int tsmode = 0; /* Time Stamp mode value */
    80. #ifdef USE_RT_SCHEDULING
    81. static int priority = -1; /* don't change priority rate */
    82. #endif
    83.  
    84. /* the following flags can be toggled on-line */
    85. unsigned int horchmode = FALSE; /* Horch-Format mode */
    86. unsigned int plugfest = FALSE;
    87.  
    88. #ifdef HAVE_TERMIOS
    89. static struct termios oldtty;
    90. #endif
    91.  
    92. void display_participant(unsigned id);
    93. void set_terminal_mode(void);
    94. void clean_up(int sig);
    95. void cut_mark(void);
    96. static void clean(void);
    97.  
    98. /* ----------------------------------------------------------------------- */
    99.  
    100. void usage(char *s)
    101. {
    102. const char *usage_text = "\
    103. Open CAN device and display read messages\n\
    104. Default device is %s. \n\
    105. Options:\n\
    106. -d - debug On\n\
    107. swich on additional debugging\n\
    108. -b baudrate (Standard uses value of /proc/sys/Can/baud)\n\
    109. -n - non-blocking mode (default blocking)\n\
    110. -B n - buffer size used in non-blocking mode (100)\n\
    111. -s sleep sleep in ms between read() calls in non-blocking mode\n\
    112. -H - output displayed in \'horch \' format\n\
    113. -l Listen only mode\n\
    114. -f self-reception mode\n\
    115. -t - time stamp mode [0123]\n\
    116. 0 - no time stamp (time stamp is zero)\n\
    117. 1 - absolute time as gettimeofday()\n\
    118. 2 - absolute rate monotonic time\n\
    119. 3 - time difference to the last event (received message)\n\
    120. 4 - absolute time, readable year-month-day h:m:s.us\n\
    121. -p p change scheduling priority of receive\n\
    122. -V version\n\
    123. -P CiA PlugFest mode (komws manufacturer CAN Ids\n\
    124. \n\
    125. ";
    126.  
    127. const char *i_usage_text = "\
    128. Interactive usage commands:\n\
    129. h - toggle horch display mode\n\
    130. f - toggle self-reception on sent frames\n\
    131. c - issue a cut-mark on stdout\n\
    132. p - display manufacturers name for CiA PlugFest\n\
    133. q - quit\n\
    134. \n\
    135. ";
    136.  
    137. fprintf(stderr, "usage: %s [options] [device]\n", s);
    138. fprintf(stderr, (const char *)usage_text, STDDEV);
    139. fprintf(stderr, (const char *)i_usage_text, STDDEV);
    140. }
    141.  
    142.  
    143. /***********************************************************************
    144. *
    145. * set_bitrate - sets the CAN bit rate
    146. *
    147. *
    148. * Changing these registers only possible in Reset mode.
    149. *
    150. * RETURN:
    151. *
    152. */
    153.  
    154. int set_bitrate(
    155. int fd, /* device descriptor */
    156. int baud /* bit rate */
    157. )
    158. {
    159. config_par_t cfg;
    160. volatile command_par_t cmd;
    161. int ret;
    162.  
    163.  
    164. cmd.cmd = CMD_STOP;
    165. ioctl(fd, CAN_IOCTL_COMMAND, &cmd);
    166.  
    167. cfg.target = CONF_TIMING;
    168. cfg.val1 = baud;
    169. ret = ioctl(fd, CAN_IOCTL_CONFIG, &cfg);
    170.  
    171. cmd.cmd = CMD_START;
    172. ioctl(fd, CAN_IOCTL_COMMAND, &cmd);
    173.  
    174. if (ret < 0) {
    175. perror("set_bitrate");
    176. exit(-1);
    177. } else {
    178. ret = 0;
    179. }
    180. return ret;
    181. }
    182.  
    183. /***********************************************************************
    184. *
    185. * set_lomode - sets the CAN in Listen Only Mode
    186. *
    187. *
    188. * Changing these registers only possible in Reset mode.
    189. *
    190. * RETURN:
    191. *
    192. */
    193. int set_lomode(int fd)
    194. {
    195. config_par_t cfg;
    196. volatile command_par_t cmd;
    197. int ret;
    198.  
    199. cmd.cmd = CMD_STOP;
    200. ioctl(fd, CAN_IOCTL_COMMAND, &cmd);
    201.  
    202. cfg.target = CONF_LISTEN_ONLY_MODE;
    203. cfg.val1 = 1;
    204. ret = ioctl(fd, CAN_IOCTL_CONFIG, &cfg);
    205.  
    206. cmd.cmd = CMD_START;
    207. ioctl(fd, CAN_IOCTL_COMMAND, &cmd);
    208.  
    209. if (ret < 0) {
    210. perror("set_lomode");
    211. exit(-1);
    212. } else {
    213. ret = 0;
    214. }
    215. return ret;
    216. }
    217.  
    218.  
    219. /***********************************************************************
    220. *
    221. *\brief set_tsmode - sets the time stamp mode for received messages
    222. *
    223. * 0 - no time stamp (time stamp is zero)
    224. * 1 - absolute time as gettimeofday()
    225. * 2 - absolute rate monotonic time
    226. * 3 - time difference to the last event (received message)
    227. *
    228. * if an ioctl() error occurs, exit() is called.
    229. *
    230. * \return 0 OK
    231. */
    232. int set_tsmode(int fd, int mode)
    233. {
    234. config_par_t cfg;
    235. int ret;
    236.  
    237.  
    238. cfg.target = CONF_TIMESTAMP;
    239. cfg.val1 = mode;
    240. ret = ioctl(fd, CAN_IOCTL_CONFIG, &cfg);
    241.  
    242.  
    243. if (ret < 0) {
    244. perror("set_tsmode");
    245. exit(-1);
    246. } else {
    247. ret = 0;
    248. }
    249. return ret;
    250. }
    251.  
    252.  
    253. /***********************************************************************
    254. * \brief set_selfreception
    255. *
    256. * toggle the self reception ability of the CAN driver
    257. *
    258. * A message frame sent out by the controller is copied into
    259. * the receive queue after successful transmission.
    260. */
    261. void set_selfreception(int fd, int v)
    262. {
    263. #if CAN4LINUXVERSION >= 0x0402 /* defined in can4linux.h */
    264. config_par_t cfg;
    265. #else
    266. Config_par_t cfg;
    267. #endif
    268.  
    269. if(debug) {
    270. printf(" set selfreception to %d\n", v);
    271. }
    272. cfg.cmd = CAN_IOCTL_CONFIG;
    273. cfg.target = CONF_SELF_RECEPTION;
    274. cfg.val1 = v;
    275. ioctl(fd, CAN_IOCTL_CONFIG, &cfg);
    276.  
    277. }
    278.  
    279.  
    280. /***********************************************************************
    281. *
    282. * main -
    283. *
    284. *
    285. */
    286.  
    287. ...
    288. TBC
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ...
    2. int main(int argc, char **argv)
    3. {
    4.  
    5. QApplication a(argc, argv);
    6. MainWindow w;
    7. w.zapisz(51);
    8. w.show();
    9.  
    10. // return a.exec();
    11.  
    12. int fd;
    13. int got;
    14. int c;
    15. char *pname;
    16. extern char *optarg;
    17. extern int optind;
    18. int bit[16];
    19. int nl;
    20. int j;
    21. for(nl=0;nl<16;nl++)
    22. {bit[nl]=0;
    23. }
    24.  
    25. canmsg_t rx[RXBUFFERSIZE];
    26. char device[50] = "/dev/can0";
    27. int messages_to_read = 1;
    28.  
    29. #ifdef USE_RT_SCHEDULING
    30. int ret;
    31. int max_rr_priority, min_rr_priority;
    32. int max_ff_priority, min_ff_priority;
    33. #else
    34. int max_priority;
    35. #endif
    36.  
    37. pname = *argv;
    38.  
    39. #ifdef USE_RT_SCHEDULING
    40. max_rr_priority = sched_get_priority_max(SCHED_RR);
    41. min_rr_priority = sched_get_priority_min(SCHED_RR);
    42. max_ff_priority = sched_get_priority_max(SCHED_FIFO);
    43. min_ff_priority = sched_get_priority_min(SCHED_FIFO);
    44. #else
    45. max_priority = 1;
    46. #endif
    47.  
    48. /* parse command line */
    49. while ((c = getopt(argc, argv, "B:b:dD:fhHlp:s:t:nPV")) != EOF) {
    50. switch (c) {
    51. case 'b':
    52. baud = atoi(optarg);
    53. break;
    54. case 'B':
    55. buffers = atoi(optarg);
    56. case 's':
    57. sleeptime = atoi(optarg);
    58. break;
    59. case 'd':
    60. debug = true;
    61. break;
    62. case 'H':
    63. horchmode = TRUE;
    64. break;
    65. case 'l': /* set listen only mode */
    66. listenmode = TRUE;
    67. break;
    68. case 'f': /* set selfreception mode */
    69. selfreception = TRUE;
    70. break;
    71. case 'n':
    72. blocking = FALSE;
    73. messages_to_read = RXBUFFERSIZE;
    74. break;
    75. case 't': /* set time stamp mode */
    76. settsmode = TRUE;
    77. tsmode = atoi(optarg);
    78. break;
    79. case 'P':
    80. plugfest = TRUE;
    81. break;
    82. case 'p':
    83. {
    84. #ifdef USE_RT_SCHEDULING
    85. struct sched_param mysched;
    86. /* use real time round-robin or real time first-in first-out */
    87. priority = atoi(optarg);
    88. if (priority < min_rr_priority ) {
    89. fprintf(stderr, "Priority < %d not allowed\n",
    90. min_rr_priority);
    91. }
    92. if (priority > max_rr_priority) {
    93. fprintf(stderr, "Priority > %d not allowed\n",
    94. max_rr_priority);
    95. }
    96. mysched.sched_priority = priority;
    97. /* sched_get_priority_max(SCHED_RR) - 1; */
    98.  
    99. ret = sched_setscheduler(0, SCHED_RR, &mysched);
    100. if ( debug == true ) {
    101. printf("sched_setscheduler() = %d\n", ret);
    102. }
    103. if(ret == -1) {
    104. printf("No permission to change process priorities\n");
    105. }
    106. /* lock all currently and in future
    107.   allocated memory blocks in physical ram */
    108. ret = mlockall(MCL_CURRENT | MCL_FUTURE);
    109. if ( debug == true ) {
    110. printf("mlockall() = %d\n", ret);
    111. }
    112.  
    113. #endif
    114. }
    115. break;
    116. case 'V':
    117. printf("%s %s %s\n", argv[0], " V " VERSION ", " __DATE__ ,
    118. #if defined(CANFD)
    119. " (CAN FD data structure used)"
    120. #else
    121. ""
    122. #endif
    123. );
    124. printf(" can4linux.h header version %d.%d\n",
    125. CAN4LINUXVERSION >> 8, CAN4LINUXVERSION & 0xFF);
    126. exit(0);
    127. break;
    128.  
    129. /* not used, device name is parameter */
    130. case 'D':
    131. if (
    132. /* path ist starting with '.' or '/', use it as it is */
    133. optarg[0] == '.'
    134. ||
    135. optarg[0] == '/'
    136. ) {
    137. snprintf(device, 50, "%s", optarg);
    138.  
    139. } else {
    140. snprintf(device, 50, "/dev/%s", optarg);
    141. }
    142. break;
    143. case 'h':
    144. default: usage(pname); exit(0);
    145. }
    146. }
    147.  
    148. /* look for additional arguments given on the command line */
    149. if ( argc - optind > 0 ) {
    150. /* at least one additional argument, the device name is given */
    151. char *darg = argv[optind];
    152.  
    153. if (
    154. /* path ist starting with '.' or '/', use it as it is */
    155. darg[0] == '.'
    156. ||
    157. darg[0] == '/'
    158. ) {
    159. snprintf(device, 50, "%s", darg);
    160. } else {
    161. snprintf(device, 50, "/dev/%s", darg);
    162. }
    163. } else {
    164. snprintf(device, 50, "%s", STDDEV);
    165. }
    166.  
    167. if (debug == true) {
    168. printf("%s %s\n", argv[0], " V " VERSION ", " __DATE__ );
    169. printf("(c) 2012-2014 H.J. Oertel\n");
    170. printf(" using canmsg_t with %d bytes\n", (int)sizeof(canmsg_t));
    171. #if defined(CANFD)
    172. printf(" CAN FD data structure used\n");
    173. #endif
    174. printf(" open CAN device \"%s\" in %sblocking mode\n",
    175. device, blocking ? "" : "non-");
    176. #ifdef USE_RT_SCHEDULING
    177. printf(" possible process RR priority is \"-p %d - %d\"\n",
    178. min_rr_priority, max_rr_priority);
    179. {
    180. int pol;
    181. struct sched_param sp;
    182.  
    183. pol = sched_getscheduler(0);
    184. sched_getparam(0, &sp);
    185. printf("using real time %s policy and priority %d\n",
    186. (pol == SCHED_OTHER) ? "OTHER" :
    187. (pol == SCHED_RR) ? "RR" :
    188. (pol == SCHED_FIFO) ? "FIFO" :
    189. #ifdef SCHED_BATCH
    190. (pol == SCHED_BATCH) ? "BATCH" :
    191. #endif
    192. #ifdef SCHED_IDLE
    193. (pol == SCHED_IDLE) ? "IDLE" :
    194. #endif
    195. "???", sp.sched_priority);
    196. }
    197. #endif /* USE_RT_SCHEDULING */
    198. }
    199.  
    200. sleeptime *= 1000;
    201.  
    202. if(blocking == TRUE) {
    203. /* fd = open(device, O_RDWR); */
    204. fd = open(device, O_RDONLY);
    205. } else {
    206. fd = open(device, O_RDONLY | O_NONBLOCK);
    207. }
    208. if( fd < 0 ) {
    209. fprintf(stderr,"Error opening CAN device %s\n", device);
    210. perror("open");
    211. exit(1);
    212. }
    213. if (baud > 0) {
    214. if ( debug == TRUE ) {
    215. printf("change Bit-Rate to %d Kbit/s\n", baud);
    216. }
    217. set_bitrate(fd, baud);
    218. }
    219. if (listenmode == TRUE) {
    220. if ( debug == TRUE ) {
    221. printf(" Change to Listen Only Mode\n");
    222. }
    223. set_lomode(fd);
    224. }
    225. if (selfreception == TRUE) {
    226. if ( debug == TRUE ) {
    227. printf(" Switch on selfreception of sent frames\n");
    228. }
    229. set_selfreception(fd, 1);
    230. }
    231. if (settsmode == TRUE) {
    232. if ( debug == TRUE ) {
    233. printf(" Change to Time Stamp Mode %d\n", tsmode);
    234. }
    235. if (tsmode == 4) {
    236. /* mode 4 uses absulte time stamp of the driver,
    237.   * but displays a *ctime string */
    238. set_tsmode(fd, 1);
    239. } else {
    240. set_tsmode(fd, tsmode);
    241. }
    242. }
    243.  
    244. /* all parameters are valid, before going into the receive loop
    245.  * set up the console stdin in raw mode to be able to change
    246.  * something at run time */
    247. atexit(clean);
    248. /* Installing Signal handler */
    249. if (signal (SIGINT, clean_up) == SIG_IGN)
    250. signal (SIGINT, SIG_IGN);
    251.  
    252. // set_terminal_mode();
    253.  
    254. /* printf("waiting for msg at %s\n", device); */
    255.  
    256. while(1) {
    257. #if 0
    258. int i;
    259.  
    260. /* check for anything at stdin */
    261. ioctl(0, FIONREAD, &i);
    262. while (i--) { /* input available */
    263. int c;
    264. /* get it */
    265. c = getchar();
    266. switch (c) {
    267. case 'c':
    268. cut_mark();
    269. break;
    270. case 'p':
    271. plugfest = !plugfest;
    272. break;
    273. case 'h':
    274. horchmode = !horchmode;
    275. break;
    276. case 'f':
    277. selfreception = !selfreception;
    278. break;
    279. case 'q':
    280. exit(0);
    281. break;
    282. default:
    283. break;
    284. }
    285. }
    286. #endif
    287. got=read(fd, &rx[0], messages_to_read);
    288. if( got > 0) {
    289. int i;
    290. int j;
    291. char *format;
    292.  
    293. for(i = 0; i < got; i++) {
    294. if(horchmode) {
    295. if (tsmode == 4) {
    296. time_t nowtime;
    297. struct tm *nowtm;
    298. char tmbuf[64];
    299. nowtime = rx[i].timestamp.tv_sec;
    300. nowtm = localtime(&nowtime);
    301. strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
    302. printf("%s.%06lu", tmbuf, rx[i].timestamp.tv_usec);
    303. } else {
    304. printf("%12lu.%06lu",
    305. rx[i].timestamp.tv_sec,
    306. rx[i].timestamp.tv_usec);
    307. }
    308. if (plugfest) {
    309. display_participant(rx[i].id);
    310. }
    311. if(rx[i].id != 0xffffffff) {
    312. printf(" %9u/0x%08x",
    313. rx[i].id, rx[i].id);
    314. } else {
    315. printf("%20s", "error");
    316. }
    317. } else {
    318. printf("Received with ret=%d: %12lu.%06lu id=%u/0x%08x\n",
    319. got,
    320. rx[i].timestamp.tv_sec,
    321. rx[i].timestamp.tv_usec,
    322. rx[i].id, rx[i].id);
    323.  
    324. printf("\tlen=%d", rx[i].length);
    325. printf(" flags=0x%02x", rx[i].flags );
    326. }
    327.  
    328. /* check if an CAN FD frame was received
    329.   * and change frame formatting rules for display */
    330. if(rx[i].flags & MSG_CANFD ) {
    331. format = " : %c%c%c [%2d]:";
    332. } else {
    333. format = " : %c%c%c (%2d): ramka danych";
    334. }
    335. printf(format,
    336. /* extended/base */
    337. (rx[i].flags & MSG_EXT) ?
    338. (rx[i].flags & MSG_SELF) ? 'E' : 'e'
    339. :
    340. (rx[i].flags & MSG_SELF) ? 'B' : 'b',
    341. /* remote/data */
    342. (rx[i].flags & MSG_RTR) ? 'R' : 'D',
    343. (rx[i].flags & MSG_RBRS) ? 'F' : ' ',
    344. rx[i].length );
    345. if( !(rx[i].flags & MSG_RTR) ) {
    346. int length;
    347. length = rx[i].length;
    348. /* check canfd flag for length calculation */
    349. if( rx[i].flags & MSG_CANFD ) {
    350. if(length > 64) length = 64;
    351. } else {
    352. /* classic CAN */
    353. /* restrict display to 8 byte */
    354. if(length > 11) length = 11;
    355. }
    356. for(j = 0; j < length; j++) {
    357. printf(" %02x", rx[i].data[j]);
    358.  
    359.  
    360.  
    361. }
    362. }
    363. ...TBC
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /* NOWY*/
    2.  
    3. //1szy bit
    4. //0
    5. if(rx[i].id==0x3AA && rx[i].data[0]==0x00)
    6. bit[0]=0;
    7. //1
    8. if(rx[i].id==0x3AA && rx[i].data[0]==0x01)
    9. bit[0]=1;
    10. //1 2
    11. if(rx[i].id==0x3AA && rx[i].data[0]==0x05)
    12. bit[0]=5;
    13. //1 3
    14. if(rx[i].id==0x3AA && rx[i].data[0]==0x11)
    15. bit[0]=11;
    16. //1 4
    17. if(rx[i].id==0x3AA && rx[i].data[0]==0x41)
    18. bit[0]=41;
    19. //2
    20. if(rx[i].id==0x3AA && rx[i].data[0]==0x04)
    21. bit[0]=4;
    22. //2 3
    23. if(rx[i].id==0x3AA && rx[i].data[0]==0x14)
    24. bit[0]=14;
    25. //2 4
    26. if(rx[i].id==0x3AA && rx[i].data[0]==0x44)
    27. bit[0]=44;
    28. //3
    29. if(rx[i].id==0x3AA && rx[i].data[0]==0x10)
    30. bit[0]=10;
    31. //3 4
    32. if(rx[i].id==0x3AA && rx[i].data[0]==0x50)
    33. bit[0]=50;
    34. //1 2 3
    35. if(rx[i].id==0x3AA && rx[i].data[0]==0x15)
    36. bit[0]=15;
    37. //1 2 4
    38. if(rx[i].id==0x3AA && rx[i].data[0]==0x45)
    39. bit[0]=45;
    40. //1 3 4
    41. if(rx[i].id==0x3AA && rx[i].data[0]==0x51)
    42. bit[0]=51;
    43. //2 3 4
    44. if(rx[i].id==0x3AA && rx[i].data[0]==0x54)
    45. bit[0]=54;
    46. //1 2 3 4
    47. if(rx[i].id==0x3AA && rx[i].data[0]==0x55)
    48. bit[0]=55;
    49. //4
    50. if(rx[i].id==0x3AA && rx[i].data[0]==0x40)
    51. bit[0]=40;
    52.  
    53. //drugi bit
    54.  
    55. //0
    56. if(rx[i].id==0x3AA && rx[i].data[1]==0x00)
    57. bit[1]=0;
    58. //1
    59. if(rx[i].id==0x3AA && rx[i].data[1]==0x01)
    60. bit[1]=1;
    61. //1 2
    62. if(rx[i].id==0x3AA && rx[i].data[1]==0x05)
    63. bit[1]=5;
    64. //1 3
    65. if(rx[i].id==0x3AA && rx[i].data[1]==0x11)
    66. bit[1]=11;
    67. //1 4
    68. if(rx[i].id==0x3AA && rx[i].data[1]==0x41)
    69. bit[1]=41;
    70. //2
    71. if(rx[i].id==0x3AA && rx[i].data[1]==0x04)
    72. bit[1]=4;
    73. //2 3
    74. if(rx[i].id==0x3AA && rx[i].data[1]==0x14)
    75. bit[1]=14;
    76. //2 4
    77. if(rx[i].id==0x3AA && rx[i].data[1]==0x44)
    78. bit[1]=44;
    79. //3
    80. if(rx[i].id==0x3AA && rx[i].data[1]==0x10)
    81. bit[1]=10;
    82. //3 4
    83. if(rx[i].id==0x3AA && rx[i].data[1]==0x50)
    84. bit[1]=50;
    85. //1 2 3
    86. if(rx[i].id==0x3AA && rx[i].data[1]==0x15)
    87. bit[1]=15;
    88. //1 2 4
    89. if(rx[i].id==0x3AA && rx[i].data[1]==0x45)
    90. bit[1]=45;
    91. //1 3 4
    92. if(rx[i].id==0x3AA && rx[i].data[1]==0x51)
    93. bit[1]=51;
    94. //2 3 4
    95. if(rx[i].id==0x3AA && rx[i].data[1]==0x54)
    96. bit[1]=54;
    97. //1 2 3 4
    98. if(rx[i].id==0x3AA && rx[i].data[1]==0x55)
    99. bit[1]=55;
    100. //4
    101. if(rx[i].id==0x3AA && rx[i].data[1]==0x40)
    102. bit[1]=40;
    103.  
    104.  
    105. //trzeci bit
    106.  
    107. //0
    108. if(rx[i].id==0x3AA && rx[i].data[2]==0x00)
    109. bit[2]=0;
    110. //1
    111. if(rx[i].id==0x3AA && rx[i].data[2]==0x01)
    112. bit[2]=1;
    113. //1 2
    114. if(rx[i].id==0x3AA && rx[i].data[2]==0x05)
    115. bit[2]=5;
    116. //1 3
    117. if(rx[i].id==0x3AA && rx[i].data[2]==0x11)
    118. bit[2]=11;
    119. //1 4
    120. if(rx[i].id==0x3AA && rx[i].data[2]==0x41)
    121. bit[2]=41;
    122. //2
    123. if(rx[i].id==0x3AA && rx[i].data[2]==0x04)
    124. bit[2]=4;
    125. //2 3
    126. if(rx[i].id==0x3AA && rx[i].data[2]==0x14)
    127. bit[2]=14;
    128. //2 4
    129. if(rx[i].id==0x3AA && rx[i].data[2]==0x44)
    130. bit[2]=44;
    131. //3
    132. if(rx[i].id==0x3AA && rx[i].data[2]==0x10)
    133. bit[2]=10;
    134. //3 4
    135. if(rx[i].id==0x3AA && rx[i].data[2]==0x50)
    136. bit[2]=50;
    137. //1 2 3
    138. if(rx[i].id==0x3AA && rx[i].data[2]==0x15)
    139. bit[2]=15;
    140. //1 2 4
    141. if(rx[i].id==0x3AA && rx[i].data[2]==0x45)
    142. bit[2]=45;
    143. //1 3 4
    144. if(rx[i].id==0x3AA && rx[i].data[2]==0x51)
    145. bit[2]=51;
    146. //2 3 4
    147. if(rx[i].id==0x3AA && rx[i].data[2]==0x54)
    148. bit[2]=54;
    149. //1 2 3 4
    150. if(rx[i].id==0x3AA && rx[i].data[2]==0x55)
    151. bit[2]=55;
    152. //4
    153. if(rx[i].id==0x3AA && rx[i].data[2]==0x40)
    154. bit[2]=40;
    155.  
    156.  
    157. //czwarty bit(13,14,15,16)
    158.  
    159. //0
    160. if(rx[i].id==0x3AA && rx[i].data[3]==0x00)
    161. bit[3]=0;
    162. //1
    163. if(rx[i].id==0x3AA && rx[i].data[3]==0x01)
    164. bit[3]=1;
    165. //1 2
    166. if(rx[i].id==0x3AA && rx[i].data[3]==0x05)
    167. bit[3]=5;
    168. //1 3
    169. if(rx[i].id==0x3AA && rx[i].data[3]==0x11)
    170. bit[3]=11;
    171. //1 4
    172. if(rx[i].id==0x3AA && rx[i].data[3]==0x41)
    173. bit[3]=41;
    174. //2
    175. if(rx[i].id==0x3AA && rx[i].data[3]==0x04)
    176. bit[3]=4;
    177. //2 3
    178. if(rx[i].id==0x3AA && rx[i].data[3]==0x14)
    179. bit[3]=14;
    180. //2 4
    181. if(rx[i].id==0x3AA && rx[i].data[3]==0x44)
    182. bit[3]=44;
    183. //3
    184. if(rx[i].id==0x3AA && rx[i].data[3]==0x10)
    185. bit[3]=10;
    186. //3 4
    187. if(rx[i].id==0x3AA && rx[i].data[3]==0x50)
    188. bit[3]=50;
    189. //1 2 3
    190. if(rx[i].id==0x3AA && rx[i].data[3]==0x15)
    191. bit[3]=15;
    192. //1 2 4
    193. if(rx[i].id==0x3AA && rx[i].data[3]==0x45)
    194. bit[3]=45;
    195. //1 3 4
    196. if(rx[i].id==0x3AA && rx[i].data[3]==0x51)
    197. bit[3]=51;
    198. //2 3 4
    199. if(rx[i].id==0x3AA && rx[i].data[3]==0x54)
    200. bit[3]=54;
    201. //1 2 3 4
    202. if(rx[i].id==0x3AA && rx[i].data[3]==0x55)
    203. bit[3]=55;
    204. //4
    205. if(rx[i].id==0x3AA && rx[i].data[3]==0x40)
    206. bit[3]=40;
    207.  
    208.  
    209.  
    210. //piaty(17,18,19,20)
    211. //0
    212. if(rx[i].id==0x3AA && rx[i].data[4]==0x00)
    213. bit[4]=0;
    214. //1
    215. if(rx[i].id==0x3AA && rx[i].data[4]==0x01)
    216. bit[4]=1;
    217. //1 2
    218. if(rx[i].id==0x3AA && rx[i].data[4]==0x05)
    219. bit[4]=5;
    220. //1 3
    221. if(rx[i].id==0x3AA && rx[i].data[4]==0x11)
    222. bit[4]=11;
    223. //1 4
    224. if(rx[i].id==0x3AA && rx[i].data[4]==0x41)
    225. bit[4]=41;
    226. //2
    227. if(rx[i].id==0x3AA && rx[i].data[4]==0x04)
    228. bit[4]=4;
    229. //2 3
    230. if(rx[i].id==0x3AA && rx[i].data[4]==0x14)
    231. bit[4]=14;
    232. //2 4
    233. if(rx[i].id==0x3AA && rx[i].data[4]==0x44)
    234. bit[4]=44;
    235. //3
    236. if(rx[i].id==0x3AA && rx[i].data[4]==0x10)
    237. bit[4]=10;
    238. //3 4
    239. if(rx[i].id==0x3AA && rx[i].data[4]==0x50)
    240. bit[4]=50;
    241. //1 2 3
    242. if(rx[i].id==0x3AA && rx[i].data[4]==0x15)
    243. bit[4]=15;
    244. //1 2 4
    245. if(rx[i].id==0x3AA && rx[i].data[4]==0x45)
    246. bit[4]=45;
    247. //1 3 4
    248. if(rx[i].id==0x3AA && rx[i].data[4]==0x51)
    249. bit[4]=51;
    250. //2 3 4
    251. if(rx[i].id==0x3AA && rx[i].data[4]==0x54)
    252. bit[4]=54;
    253. //1 2 3 4
    254. if(rx[i].id==0x3AA && rx[i].data[4]==0x55)
    255. bit[4]=55;
    256. //4
    257. if(rx[i].id==0x3AA && rx[i].data[4]==0x40)
    258. bit[4]=40;
    259.  
    260. //SZOSTY(21,22,23,24)
    261. //0
    262. if(rx[i].id==0x3AA && rx[i].data[5]==0x00)
    263. bit[5]=0;
    264. //1
    265. if(rx[i].id==0x3AA && rx[i].data[5]==0x01)
    266. bit[5]=1;
    267. //1 2
    268. if(rx[i].id==0x3AA && rx[i].data[5]==0x05)
    269. bit[5]=5;
    270. //1 3
    271. if(rx[i].id==0x3AA && rx[i].data[5]==0x11)
    272. bit[5]=11;
    273. //1 4
    274. if(rx[i].id==0x3AA && rx[i].data[5]==0x41)
    275. bit[5]=41;
    276. //2
    277. if(rx[i].id==0x3AA && rx[i].data[5]==0x04)
    278. bit[5]=4;
    279. //2 3
    280. if(rx[i].id==0x3AA && rx[i].data[5]==0x14)
    281. bit[5]=14;
    282. //2 4
    283. if(rx[i].id==0x3AA && rx[i].data[5]==0x44)
    284. bit[5]=44;
    285. //3
    286. if(rx[i].id==0x3AA && rx[i].data[5]==0x10)
    287. bit[5]=10;
    288. //3 4
    289. if(rx[i].id==0x3AA && rx[i].data[5]==0x50)
    290. bit[5]=50;
    291. //1 2 3
    292. if(rx[i].id==0x3AA && rx[i].data[5]==0x15)
    293. bit[5]=15;
    294. //1 2 4
    295. if(rx[i].id==0x3AA && rx[i].data[5]==0x45)
    296. bit[5]=45;
    297. //1 3 4
    298. if(rx[i].id==0x3AA && rx[i].data[5]==0x51)
    299. bit[5]=51;
    300. //2 3 4
    301. if(rx[i].id==0x3AA && rx[i].data[5]==0x54)
    302. bit[5]=54;
    303. //1 2 3 4
    304. if(rx[i].id==0x3AA && rx[i].data[5]==0x55)
    305. bit[5]=55;
    306. //4
    307. if(rx[i].id==0x3AA && rx[i].data[5]==0x40)
    308. bit[5]=40;
    309.  
    310.  
    311. //7! (25,26,27,28)
    312. //0
    313. if(rx[i].id==0x3AA && rx[i].data[6]==0x00)
    314. bit[6]=0;
    315. //1
    316. if(rx[i].id==0x3AA && rx[i].data[6]==0x01)
    317. bit[6]=1;
    318. //1 2
    319. if(rx[i].id==0x3AA && rx[i].data[6]==0x05)
    320. bit[6]=5;
    321. //1 3
    322. if(rx[i].id==0x3AA && rx[i].data[6]==0x11)
    323. bit[6]=11;
    324. //1 4
    325. if(rx[i].id==0x3AA && rx[i].data[6]==0x41)
    326. bit[6]=41;
    327. //2
    328. if(rx[i].id==0x3AA && rx[i].data[6]==0x04)
    329. bit[6]=4;
    330. //2 3
    331. if(rx[i].id==0x3AA && rx[i].data[6]==0x14)
    332. bit[6]=14;
    333. //2 4
    334. if(rx[i].id==0x3AA && rx[i].data[6]==0x44)
    335. bit[6]=44;
    336. //3
    337. if(rx[i].id==0x3AA && rx[i].data[6]==0x10)
    338. bit[6]=10;
    339. //3 4
    340. if(rx[i].id==0x3AA && rx[i].data[6]==0x50)
    341. bit[6]=50;
    342. //1 2 3
    343. if(rx[i].id==0x3AA && rx[i].data[6]==0x15)
    344. bit[6]=15;
    345. //1 2 4
    346. if(rx[i].id==0x3AA && rx[i].data[6]==0x45)
    347. bit[6]=45;
    348. //1 3 4
    349. if(rx[i].id==0x3AA && rx[i].data[6]==0x51)
    350. bit[6]=51;
    351. //2 3 4
    352. if(rx[i].id==0x3AA && rx[i].data[6]==0x54)
    353. bit[6]=54;
    354. //1 2 3 4
    355. if(rx[i].id==0x3AA && rx[i].data[6]==0x55)
    356. bit[6]=55;
    357. //4
    358. if(rx[i].id==0x3AA && rx[i].data[6]==0x40)
    359. bit[6]=40;
    360.  
    361. //8(29,30,31,32)
    362. //0
    363. if(rx[i].id==0x3AA && rx[i].data[7]==0x00)
    364. bit[7]=0;
    365. //1
    366. if(rx[i].id==0x3AA && rx[i].data[7]==0x01)
    367. bit[7]=1;
    368. //1 2
    369. if(rx[i].id==0x3AA && rx[i].data[7]==0x05)
    370. bit[7]=5;
    371. //1 3
    372. if(rx[i].id==0x3AA && rx[i].data[7]==0x11)
    373. bit[7]=11;
    374. //1 4
    375. if(rx[i].id==0x3AA && rx[i].data[7]==0x41)
    376. bit[7]=41;
    377. //2
    378. if(rx[i].id==0x3AA && rx[i].data[7]==0x04)
    379. bit[7]=4;
    380. //2 3
    381. if(rx[i].id==0x3AA && rx[i].data[7]==0x14)
    382. bit[7]=14;
    383. //2 4
    384. if(rx[i].id==0x3AA && rx[i].data[7]==0x44)
    385. bit[7]=44;
    386. //3
    387. if(rx[i].id==0x3AA && rx[i].data[7]==0x10)
    388. bit[7]=10;
    389. //3 4
    390. if(rx[i].id==0x3AA && rx[i].data[7]==0x50)
    391. bit[7]=50;
    392. //1 2 3
    393. if(rx[i].id==0x3AA && rx[i].data[7]==0x15)
    394. bit[7]=15;
    395. //1 2 4
    396. if(rx[i].id==0x3AA && rx[i].data[7]==0x45)
    397. bit[7]=45;
    398. //1 3 4
    399. if(rx[i].id==0x3AA && rx[i].data[7]==0x51)
    400. bit[7]=51;
    401. //2 3 4
    402. if(rx[i].id==0x3AA && rx[i].data[7]==0x54)
    403. bit[7]=54;
    404. //1 2 3 4
    405. if(rx[i].id==0x3AA && rx[i].data[7]==0x55)
    406. bit[7]=55;
    407. //4
    408. if(rx[i].id==0x3AA && rx[i].data[7]==0x40)
    409. bit[7]=40;
    410.  
    411. //9(33,34,35,36)
    412. //0
    413. if(rx[i].id==0x3AB && rx[i].data[8]==0x00)
    414. bit[8]=0;
    415. //1
    416. if(rx[i].id==0x3AB && rx[i].data[8]==0x01)
    417. bit[8]=1;
    418. //1 2
    419. if(rx[i].id==0x3AB && rx[i].data[8]==0x05)
    420. bit[8]=5;
    421. //1 3
    422. if(rx[i].id==0x3AB && rx[i].data[8]==0x11)
    423. bit[8]=11;
    424. //1 4
    425. if(rx[i].id==0x3AB && rx[i].data[8]==0x41)
    426. bit[8]=41;
    427. //2
    428. if(rx[i].id==0x3AB && rx[i].data[8]==0x04)
    429. bit[8]=4;
    430. //2 3
    431. if(rx[i].id==0x3AB && rx[i].data[8]==0x14)
    432. bit[8]=14;
    433. //2 4
    434. if(rx[i].id==0x3AB && rx[i].data[8]==0x44)
    435. bit[8]=44;
    436. //3
    437. if(rx[i].id==0x3AB && rx[i].data[8]==0x10)
    438. bit[8]=10;
    439. //3 4
    440. if(rx[i].id==0x3AB && rx[i].data[8]==0x50)
    441. bit[8]=50;
    442. //1 2 3
    443. if(rx[i].id==0x3AB && rx[i].data[8]==0x15)
    444. bit[8]=15;
    445. //1 2 4
    446. if(rx[i].id==0x3AB && rx[i].data[8]==0x45)
    447. bit[8]=45;
    448. //1 3 4
    449. if(rx[i].id==0x3AB && rx[i].data[8]==0x51)
    450. bit[8]=51;
    451. //2 3 4
    452. if(rx[i].id==0x3AB && rx[i].data[8]==0x54)
    453. bit[8]=54;
    454. //1 2 3 4
    455. if(rx[i].id==0x3AB && rx[i].data[8]==0x55)
    456. bit[8]=55;
    457. //4
    458. if(rx[i].id==0x3AB && rx[i].data[8]==0x40)
    459. bit[8]=40;
    460.  
    461.  
    462. ...TBC
    To copy to clipboard, switch view to plain text mode 


    Added after 4 minutes:


    //10(37,38,39,40)
    //0
    if(rx[i].id==0x3AB && rx[i].data[9]==0x00)
    bit[9]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[9]==0x01)
    bit[9]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[9]==0x05)
    bit[9]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[9]==0x11)
    bit[9]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x41)
    bit[9]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[9]==0x04)
    bit[9]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[9]==0x14)
    bit[9]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x44)
    bit[9]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[9]==0x10)
    bit[9]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x50)
    bit[9]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[9]==0x15)
    bit[9]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x45)
    bit[9]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x51)
    bit[9]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x54)
    bit[9]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x55)
    bit[9]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[9]==0x40)
    bit[9]=40;

    //11(41,42,43,44)
    //0
    if(rx[i].id==0x3AB && rx[i].data[10]==0x00)
    bit[10]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[10]==0x01)
    bit[10]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[10]==0x05)
    bit[10]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[10]==0x11)
    bit[10]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x41)
    bit[10]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[10]==0x04)
    bit[10]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[10]==0x14)
    bit[10]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x44)
    bit[10]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[10]==0x10)
    bit[10]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x50)
    bit[10]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[10]==0x15)
    bit[10]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x45)
    bit[10]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x51)
    bit[10]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x54)
    bit[10]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x55)
    bit[10]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[10]==0x40)
    bit[10]=40;

    //12(45,46,47,48)
    //0
    if(rx[i].id==0x3AB && rx[i].data[12]==0x00)
    bit[12]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[12]==0x01)
    bit[12]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[12]==0x05)
    bit[12]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[12]==0x11)
    bit[12]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x41)
    bit[12]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[12]==0x04)
    bit[12]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[12]==0x14)
    bit[12]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x44)
    bit[12]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[12]==0x10)
    bit[12]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x50)
    bit[12]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[12]==0x15)
    bit[12]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x45)
    bit[12]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x51)
    bit[12]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x54)
    bit[12]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x55)
    bit[12]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[12]==0x40)
    bit[12]=40;

    //13(49,50,51,52)
    //0
    if(rx[i].id==0x3AB && rx[i].data[13]==0x00)
    bit[13]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[13]==0x01)
    bit[13]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[13]==0x05)
    bit[13]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[13]==0x11)
    bit[13]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x41)
    bit[13]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[13]==0x04)
    bit[13]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[13]==0x14)
    bit[13]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x44)
    bit[13]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[13]==0x10)
    bit[13]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x50)
    bit[13]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[13]==0x15)
    bit[13]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x45)
    bit[13]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x51)
    bit[13]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x54)
    bit[13]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x55)
    bit[13]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[13]==0x40)
    bit[13]=40;

    //14(53,54,55,56)
    //0
    if(rx[i].id==0x3AB && rx[i].data[14]==0x00)
    bit[14]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[14]==0x01)
    bit[14]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[14]==0x05)
    bit[14]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[14]==0x11)
    bit[14]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x41)
    bit[14]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[14]==0x04)
    bit[14]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[14]==0x14)
    bit[14]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x44)
    bit[14]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[14]==0x10)
    bit[14]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x50)
    bit[14]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[14]==0x15)
    bit[14]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x45)
    bit[14]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x51)
    bit[14]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x54)
    bit[14]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x55)
    bit[14]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[14]==0x40)
    bit[14]=40;

    //15(57,58,59,60)
    //0
    if(rx[i].id==0x3AB && rx[i].data[15]==0x00)
    bit[15]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[15]==0x01)
    bit[15]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[15]==0x05)
    bit[15]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[15]==0x11)
    bit[15]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x41)
    bit[15]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[15]==0x04)
    bit[15]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[15]==0x14)
    bit[15]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x44)
    bit[15]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[15]==0x10)
    bit[15]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x50)
    bit[15]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[15]==0x15)
    bit[15]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x45)
    bit[15]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x51)
    bit[15]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x54)
    bit[15]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x55)
    bit[15]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[15]==0x40)
    bit[15]=40;

    //16(61,62,63,64)
    //0
    if(rx[i].id==0x3AB && rx[i].data[16]==0x00)
    bit[16]=0;
    //1
    if(rx[i].id==0x3AB && rx[i].data[16]==0x01)
    bit[16]=1;
    //1 2
    if(rx[i].id==0x3AB && rx[i].data[16]==0x05)
    bit[16]=5;
    //1 3
    if(rx[i].id==0x3AB && rx[i].data[16]==0x11)
    bit[16]=11;
    //1 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x41)
    bit[16]=41;
    //2
    if(rx[i].id==0x3AB && rx[i].data[16]==0x04)
    bit[16]=4;
    //2 3
    if(rx[i].id==0x3AB && rx[i].data[16]==0x14)
    bit[16]=14;
    //2 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x44)
    bit[16]=44;
    //3
    if(rx[i].id==0x3AB && rx[i].data[16]==0x10)
    bit[16]=10;
    //3 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x50)
    bit[16]=50;
    //1 2 3
    if(rx[i].id==0x3AB && rx[i].data[16]==0x15)
    bit[16]=15;
    //1 2 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x45)
    bit[16]=45;
    //1 3 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x51)
    bit[16]=51;
    //2 3 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x54)
    bit[16]=54;
    //1 2 3 4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x55)
    bit[16]=55;
    //4
    if(rx[i].id==0x3AB && rx[i].data[16]==0x40)
    bit[16]=40;



    w.zapisz(51);
    for(j=0;j<16;j++)
    { if(bit[j]==0)
    printf(" %d - 0",j+1);
    if(bit[j]==1)
    printf(" %d - %d",j+1,1+4*j);
    if(bit[j]==5)
    printf(" %d - %d %d",j+1, 1, 2);
    if(bit[j]==11)
    printf(" %d - %d %d",j+1, 1+4*j,3+4*j);
    if(bit[j]==41)
    printf(" %d - %d %d",j+1, 1+4*j, 4+4*j);
    if(bit[j]==4)
    printf(" %d - %d",j+1, 2+4*j);
    if(bit[j]==14)
    printf(" %d - %d %d",j+1,2+4*j,3+4*j);
    if(bit[j]==44)
    printf(" %d - %d %d",j+1,2+4*j,4+4*j);
    if(bit[j]==10)
    printf(" %d - %d",j+1,3+4*j);
    if(bit[j]==50)
    printf(" %d - %d %d",j+1,3+4*j,4+4*j);
    if(bit[j]==15)
    printf(" %d - %d %d %d",j+1,1+4*j,2+4*j,3+4*j);
    if(bit[j]==45)
    printf(" %d - %d %d %d",j+1,1+4*j,2+4*j,4+4*j);
    if(bit[j]==51)
    printf(" %d - %d %d %d",j+1,1+4*j,3+4*j,4+4*j);
    if(bit[j]==54)
    printf(" %d - %d %d %d",j+1,2+4*j,3+4*j,4+4*j);
    if(bit[j]==55)
    printf(" %d - %d %d %d %d",j+1,1+4*j,2+4*j,3+4*j,4+4*j);
    if(bit[j]==40)
    printf(" %d - %d",j+1,4+4*j);
    }



    if(horchmode && (rx[i].id == -1)) {
    unsigned char f = ' ';
    printf(" Error flags=0x%03x\n\tError: ", rx[i].flags);
    if(rx[i].flags & MSG_OVR) {
    printf("%c CAN controller msg overflow", f);
    f = ',';
    }
    if(rx[i].flags & MSG_PASSIVE) {
    printf("%c CAN Error Passive", f);
    f = ',';
    }
    if(rx[i].flags & MSG_BUSOFF) {
    printf("%c CAN controller Bus off", f);
    f = ',';
    }
    if(rx[i].flags & MSG_WARNING) {
    printf("%c CAN controller Error Warnig Level reached", f);
    f = ',';
    }
    if(rx[i].flags & MSG_BOVR) {
    printf("%c can4linux rx/tx buffer overflow", f);
    f = ',';
    }
    }
    printf("\n"); fflush(stdout);
    }
    } else {
    printf("Received with ret=%d\n", got);
    fflush(stdout);
    }
    if(blocking == FALSE) {
    /* wait some time before doing the next read() */
    usleep(sleeptime);
    }
    }

    close(fd);

    return 0;

    printf("trying to call python for logging\n");
    [/CODE]

    Qt Code:
    1. ...
    2.  
    3. //I must to commend of this, because it made errors.
    4.  
    5. //Py_Initialize();
    6. //PyRun_SimpleString("x = 78");
    7. //PyRun_SimpleString("print x");
    8. //PyRun_SimpleString("import logging");
    9. //PyRun_SimpleString("logger = logging.getLogger('myapp')");
    10. //PyRun_SimpleString("hdlr = logging.FileHandler('/usr/local/logging/myapp.log')");
    11. //PyRun_SimpleString("formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')");
    12. //PyRun_SimpleString("hdlr.setFormatter(formatter)");
    13. //PyRun_SimpleString("logger.addHandler(hdlr)");
    14. //PyRun_SimpleString("logger.setLevel(logging.INFO)");
    15. //PyRun_SimpleString("logger.error('andther log message with x value: %d',x)");
    16. //Py_Finalize();
    17.  
    18. return 0;
    19.  
    20. }
    21.  
    22. /**************************************************************************
    23. *
    24. * clean_up
    25. *
    26. */
    27. void clean_up(int sig)
    28. {
    29. (void)sig; /* not evaluated */
    30. #ifdef USER_TERMIOS
    31. tcsetattr (0, TCSANOW, &oldtty);
    32. #endif
    33. /* clean(); */ /* clean wird per atexit() eingebunden */
    34. exit(0);
    35. }
    36.  
    37. void set_terminal_mode(void)
    38. {
    39. #ifdef USER_TERMIOS
    40. struct termios tty;
    41.  
    42. fprintf(stderr, "Setting RAW terminal mode\n");
    43.  
    44. tcgetattr (0, &tty);
    45. oldtty = tty;
    46.  
    47. tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
    48. |INLCR|IGNCR|ICRNL|IXON);
    49. tty.c_oflag |= OPOST;
    50. tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
    51. tty.c_cflag &= ~(CSIZE|PARENB);
    52. tty.c_cflag |= CS8;
    53. tty.c_cc[VMIN] = 1;
    54. tty.c_cc[VTIME] = 0;
    55.  
    56. tcsetattr (0, TCSANOW, &tty);
    57. signal(SIGQUIT, clean_up); /* Quit (POSIX). */
    58. #else
    59. //fprintf(stderr, "Setting RAW terminal mode using stty\n");
    60. int ret = system("stty cbreak -echo");
    61. if(ret != 0) {
    62. fprintf(stderr, " system(stty) returns %d\n", ret);
    63. fflush(stderr);
    64. }
    65. #endif
    66. }
    67.  
    68. /***********************************************************************
    69. * cut_mark - draw a line on the console
    70. *
    71. */
    72. void cut_mark(void)
    73. {
    74. static char line[70] = "------------------------------------------------------------\r\n";
    75. puts(line);
    76. }
    77.  
    78. /**************************************************************************
    79. *
    80. * clean
    81. *
    82. */
    83. static void clean(void)
    84. {
    85. (void)system("stty sane");
    86. }
    87.  
    88.  
    89. /* at the CiA Plugfest
    90.  * participants are coded in the last 4 bits of the CAN Id */
    91. void display_participant(unsigned id)
    92. {
    93. char *participants[16] = {
    94. "BOSCH", /* 0 */
    95. "Vector",
    96. "Peak",
    97. "Infineon",
    98. "Renesas",
    99. "Spansion",
    100. "ESD",
    101. "STM",
    102. "IXXAT",
    103. "",
    104. "", /* 0x0a -- 10 */
    105. "",
    106. "NI",
    107. "IFI emtas", /* 0x0d */
    108. NULL,
    109. };
    110. printf(" %11s ", participants[id & 0x0f]);
    111. }
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. int bit2;
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. QPixmap pix("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_grn.bmp");
    12. QPixmap pix2("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_red.bmp");
    13.  
    14. ui->label->setPixmap(pix);
    15. ui->label_2->setPixmap(pix);
    16. ui->label_3->setPixmap(pix);
    17. ui->label_4->setPixmap(pix);
    18. flag=0;
    19. int bit;
    20. bit=bit2;//COS NIE GRA, NIE POBIERA WIADOMOSCI Z MAINWINDOW.H ALE RECZNIE WCISNIETE JEST GIT ;/
    21.  
    22. if(bit==0)
    23. {
    24.  
    25. ui->label->setPixmap(pix);
    26. ui->label_2->setPixmap(pix);
    27. ui->label_3->setPixmap(pix);
    28. ui->label_4->setPixmap(pix);
    29. }
    30. if(bit==1)
    31. {
    32. ui->label->setPixmap(pix2);
    33. ui->label_2->setPixmap(pix);
    34. ui->label_3->setPixmap(pix);
    35. ui->label_4->setPixmap(pix);
    36. }
    37.  
    38. if(bit==5)
    39. {
    40. ui->label->setPixmap(pix2);
    41. ui->label_2->setPixmap(pix2);
    42. ui->label_3->setPixmap(pix);
    43. ui->label_4->setPixmap(pix);
    44. }
    45. if(bit==11)
    46. {
    47. ui->label->setPixmap(pix2);
    48. ui->label_2->setPixmap(pix);
    49. ui->label_3->setPixmap(pix2);
    50. ui->label_4->setPixmap(pix);
    51. }
    52. if(bit==41)
    53. {
    54. ui->label->setPixmap(pix2);
    55. ui->label_2->setPixmap(pix);
    56. ui->label_3->setPixmap(pix);
    57. ui->label_4->setPixmap(pix2);
    58. }
    59. if(bit==4)
    60. {
    61. ui->label->setPixmap(pix);
    62. ui->label_2->setPixmap(pix2);
    63. ui->label_3->setPixmap(pix);
    64. ui->label_4->setPixmap(pix);
    65.  
    66. }
    67. if(bit==14)
    68. {
    69. ui->label->setPixmap(pix);
    70. ui->label_2->setPixmap(pix2);
    71. ui->label_3->setPixmap(pix2);
    72. ui->label_4->setPixmap(pix);
    73. }
    74. if(bit==44)
    75. {
    76. ui->label->setPixmap(pix);
    77. ui->label_2->setPixmap(pix2);
    78. ui->label_3->setPixmap(pix);
    79. ui->label_4->setPixmap(pix2);
    80.  
    81. }
    82. if(bit==10)
    83. {
    84. ui->label->setPixmap(pix);
    85. ui->label_2->setPixmap(pix);
    86. ui->label_3->setPixmap(pix2);
    87. ui->label_4->setPixmap(pix);
    88. }
    89. if(bit==50)
    90. {ui->label->setPixmap(pix);
    91. ui->label_2->setPixmap(pix);
    92. ui->label_3->setPixmap(pix2);
    93. ui->label_4->setPixmap(pix2);
    94. }
    95. if(bit==15)
    96. {ui->label->setPixmap(pix2);
    97. ui->label_2->setPixmap(pix2);
    98. ui->label_3->setPixmap(pix2);
    99. ui->label_4->setPixmap(pix);
    100.  
    101. }
    102. if(bit==45)
    103. {ui->label->setPixmap(pix2);
    104. ui->label_2->setPixmap(pix2);
    105. ->label_4->setPixmap(pix2);}
    106. }
    107.  
    108. void MainWindow::zapisz(int wartosc)
    109. {
    110. bit=wartosc;
    111. }
    112.  
    113. MainWindow::~MainWindow()
    114. {
    115. delete ui;
    116. }
    To copy to clipboard, switch view to plain text mode 

    I have no idea where I should write return a.exec(); If it ¨commented¨ I have problem:

    tarting /home/bananapi/wizualizaAA-build-desktop-Qt_4_8_2__System__Release/wizualizaAA...
    Error opening CAN device /dev/can0
    open: Permission denied
    /home/bananapi/wizualizaAA-build-desktop-Qt_4_8_2__System__Release/wizualizaAA exited with code 1

    And if i write somethink like that:
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3.  
    4. QApplication a(argc, argv);
    5. MainWindow w;
    6. w.zapisz(51);
    7. w.show();
    8.  
    9. return a.exec();
    10. ...
    To copy to clipboard, switch view to plain text mode 
    bit is still don´t have value ¨51¨.


    Added after 18 minutes:


    Sry, in mainwindow.h is bit2, and in mainwindow.cpp in zapisz(int wartosc) is bit2 too.
    Last edited by adis1001; 13th July 2015 at 08:01.

  11. #11
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Delete line 19 in MainWindow.cpp. You already declared bit as a member variable, by defining it again, you are creating what is commonly referred to as a shadow variable.

    Edit: Also delete the global variable on line 4 in MainWindow.cpp.
    Last edited by jefftee; 13th July 2015 at 08:23.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Also bit (or bit2) are uninitialized at the time you read them in the constructor.

    If you need "bit" to have a value inside the constructor of the main window, then you need to pass the value as a constructor argument.
    Setting it later on with a method will have no effect on code that has already been executed.

    Cheers,
    _

  13. #13

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    Ok, so I didn´t have Timer. Now programm is working, so thank everyone

  14. #14
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Problem with variable in main.cpp and mainwindow.cpp

    I don't know what a timer has to do with anything in this thread, but glad you have it working!
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Refresh the mainwindow / functions called in the main loop
    By valerianst in forum Qt Programming
    Replies: 7
    Last Post: 2nd October 2013, 15:57
  2. how can dialog access variable from parent MainWindow?
    By krezix in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2012, 01:20
  3. Replies: 1
    Last Post: 20th January 2012, 05:39
  4. Replies: 3
    Last Post: 12th April 2011, 11:58
  5. main.cpp variable access question
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 10th March 2008, 21:48

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.