why when implement interrupt handler in qt give beolw error ? How to resolve it ?
-
error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&MainWindow::gpo_handler' [-fpermissive]
while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK);
^error: cannot convert 'void (MainWindow::)()' to 'interrupt_handler_t {aka void ()()}' for argument '1' to 'int32_t ST25DV_GPO_interrupt_init(interrupt_handler_t)'
while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK); -
@JonB So How to implement the interrupt handler for any i2c device using qt ?
@Qt-embedded-developer Use a normal function as interrupt handler, not a method in a class. In that function you can then call methods of your class if you need to do so.
-
error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&MainWindow::gpo_handler' [-fpermissive]
while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK);
^error: cannot convert 'void (MainWindow::)()' to 'interrupt_handler_t {aka void ()()}' for argument '1' to 'int32_t ST25DV_GPO_interrupt_init(interrupt_handler_t)'
while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK);@Qt-embedded-developer
So what type is/what is your declaration of yourgpo_handler
? -
@Qt-embedded-developer
So what type is/what is your declaration of yourgpo_handler
?Declaration is
void gpo_handler(void);
And defination is
void MainWindow::gpo_handler() { ST25DV_FIELD_STATUS fieldpresence; BSP_NFCTAG_GetRFField_Dyn(0, &fieldpresence ); //printf("fielpresence enum = %d", fieldpresence); if( fieldpresence == ST25DV_FIELD_ON ) { printf ("GPO handler: field is ON\r\n"); } else { printf ("GPO handler: field is OFF\r\n"); } uint8_t itstatus; // if( GPO_Activated == 1 ) // { //GPO_Activated = 0; ST25_RETRY(BSP_NFCTAG_ReadITSTStatus_Dyn(0, &itstatus )); if( (itstatus & ST25DV_ITSTS_DYN_FIELDFALLING_MASK) == ST25DV_ITSTS_DYN_RFWRITE_MASK ) { printf("RF write"); } else printf(" %x",(itstatus & ST25DV_ITSTS_DYN_FIELDFALLING_MASK)); //} }
-
Declaration is
void gpo_handler(void);
And defination is
void MainWindow::gpo_handler() { ST25DV_FIELD_STATUS fieldpresence; BSP_NFCTAG_GetRFField_Dyn(0, &fieldpresence ); //printf("fielpresence enum = %d", fieldpresence); if( fieldpresence == ST25DV_FIELD_ON ) { printf ("GPO handler: field is ON\r\n"); } else { printf ("GPO handler: field is OFF\r\n"); } uint8_t itstatus; // if( GPO_Activated == 1 ) // { //GPO_Activated = 0; ST25_RETRY(BSP_NFCTAG_ReadITSTStatus_Dyn(0, &itstatus )); if( (itstatus & ST25DV_ITSTS_DYN_FIELDFALLING_MASK) == ST25DV_ITSTS_DYN_RFWRITE_MASK ) { printf("RF write"); } else printf(" %x",(itstatus & ST25DV_ITSTS_DYN_FIELDFALLING_MASK)); //} }
@Qt-embedded-developer
So doesn't the error message tell you exactly it wants&MainWindow::gpo_handler
?P.S.
void gpo_handler(void);
That's C-ish. C++ is happy with
void gpo_handler();
. -
@Qt-embedded-developer
So doesn't the error message tell you exactly it wants&MainWindow::gpo_handler
?P.S.
void gpo_handler(void);
That's C-ish. C++ is happy with
void gpo_handler();
.first error resolved but 2nd error still come
error: cannot convert 'void (MainWindow::)()' to 'interrupt_handler_t {aka void ()()}' for argument '1' to 'int32_t ST25DV_GPO_interrupt_init(interrupt_handler_t)'
while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK); -
first error resolved but 2nd error still come
error: cannot convert 'void (MainWindow::)()' to 'interrupt_handler_t {aka void ()()}' for argument '1' to 'int32_t ST25DV_GPO_interrupt_init(interrupt_handler_t)'
while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK);@Qt-embedded-developer It looks like the interrupt handler takes an int32_t parameter.
Check the interrupt_handler_t data type. -
@Qt-embedded-developer It looks like the interrupt handler takes an int32_t parameter.
Check the interrupt_handler_t data type.@jsulm
From the error message (aka void ()()
) and from looking at definitions ofinterrupt_handler_t
on the web I do not think that is so. It seems to betypedef void @far (*interrupt_handler_t)(void);
This is beyond my expertise of C++ now, but is there a problem with passing a C++ member function here??
-
@jsulm
From the error message (aka void ()()
) and from looking at definitions ofinterrupt_handler_t
on the web I do not think that is so. It seems to betypedef void @far (*interrupt_handler_t)(void);
This is beyond my expertise of C++ now, but is there a problem with passing a C++ member function here??
@JonB @Qt-embedded-developer I don't think a method can be used here as interrupt handler. @Qt-embedded-developer use a normal function and call your MainWindow there (also, it is strange that MainWindow handles interrupts).
-
@Qt-embedded-developer It looks like the interrupt handler takes an int32_t parameter.
Check the interrupt_handler_t data type.@jsulm said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
interrupt_handler_t
This 3 thing is related to your question and my 2nd error.
1] in source.h
static interrupt_handler_t interrupt_handler;2] in source.c
typedef void (*interrupt_handler_t)(void) ;3] in source.c
int32_t ST25DV_GPO_interrupt_init(interrupt_handler_t fh) { pthread_t intr_thread; struct sched_param params; int ret; if(fh == NULL) { fprintf(stderr,"Handler is not set\r\n"); return ERR_PARAM; } interrupt_handler = fh; /* create a pthread to poll for interrupt */ ret = pthread_create(&intr_thread, NULL, ST25DV_GPO_pthread_func, NULL); if (ret) { fprintf(stderr, "Error: poll thread creation %d\r\n", ret); return ERR_IO; } /* Assign highest priority to polling thread */ params.sched_priority = sched_get_priority_max(SCHED_FIFO); ret = pthread_setschedparam(intr_thread, SCHED_FIFO, ¶ms); if (ret) { fprintf(stderr,"Error: assigning high priority to polling thread\r\n"); return ERR_IO; } return ERR_NONE; }
-
@jsulm said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
interrupt_handler_t
This 3 thing is related to your question and my 2nd error.
1] in source.h
static interrupt_handler_t interrupt_handler;2] in source.c
typedef void (*interrupt_handler_t)(void) ;3] in source.c
int32_t ST25DV_GPO_interrupt_init(interrupt_handler_t fh) { pthread_t intr_thread; struct sched_param params; int ret; if(fh == NULL) { fprintf(stderr,"Handler is not set\r\n"); return ERR_PARAM; } interrupt_handler = fh; /* create a pthread to poll for interrupt */ ret = pthread_create(&intr_thread, NULL, ST25DV_GPO_pthread_func, NULL); if (ret) { fprintf(stderr, "Error: poll thread creation %d\r\n", ret); return ERR_IO; } /* Assign highest priority to polling thread */ params.sched_priority = sched_get_priority_max(SCHED_FIFO); ret = pthread_setschedparam(intr_thread, SCHED_FIFO, ¶ms); if (ret) { fprintf(stderr,"Error: assigning high priority to polling thread\r\n"); return ERR_IO; } return ERR_NONE; }
@Qt-embedded-developer said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
typedef void (*interrupt_handler_t)(void) ;
This is a function pointer type, not a pointer to a method, so you can't use a method as interrupt handler. Use a normal function.
-
@Qt-embedded-developer said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
typedef void (*interrupt_handler_t)(void) ;
This is a function pointer type, not a pointer to a method, so you can't use a method as interrupt handler. Use a normal function.
@jsulm said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
This is a function pointer type, not a pointer to a method
This is kind of what I thought/asked you.
I am not familiar with this distinction between "a function pointer type" versus "a pointer to a method". Could you explain, or point me to a description, please?
EDIT
Ah, is this to do with class (non-static) method will need an instance and of course that is not appropriate here? -
@jsulm said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
This is a function pointer type, not a pointer to a method
This is kind of what I thought/asked you.
I am not familiar with this distinction between "a function pointer type" versus "a pointer to a method". Could you explain, or point me to a description, please?
EDIT
Ah, is this to do with class (non-static) method will need an instance and of course that is not appropriate here? -
@jsulm said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
This is a function pointer type, not a pointer to a method
This is kind of what I thought/asked you.
I am not familiar with this distinction between "a function pointer type" versus "a pointer to a method". Could you explain, or point me to a description, please?
EDIT
Ah, is this to do with class (non-static) method will need an instance and of course that is not appropriate here?@JonB said in why when implement interrupt handler in qt give beolw error ? How to resolve it ?:
Ah, is this to do with class (non-static) method will need an instance and of course that is not appropriate here?
Yes, you need an instance.
-
@JonB Well, method pointers are funny:
typedef void (MainWindow::*MethodPointer)(); MethodPointer p = &MainWindow::doSomething; // Calling (this->*p)();
@jsulm
I did a Google and came up with https://isocpp.org/wiki/faq/pointers-to-members#fnptr-vs-memfnptr-typesIs the type of “pointer-to-member-function” different from “pointer-to-function”?
Yep.Consider the following function:
int f(char a, float b);
The type of this function is different depending on whether it is an ordinary function or a non-static member function of some class:Its type is “int ()(char,float)” if an ordinary function
Its type is “int (Fred::)(char,float)” if a non-static member function of class Fred
Note: if it’s a static member function of class Fred, its type is the same as if it were an ordinary function: “int (*)(char,float)”.Separately:
Yes, you need an instance.
Yes, that's kind of a different issue, in that it's not going to work anyway for the OP. But I was concentrating on the compiler error message.
-
@jsulm
I did a Google and came up with https://isocpp.org/wiki/faq/pointers-to-members#fnptr-vs-memfnptr-typesIs the type of “pointer-to-member-function” different from “pointer-to-function”?
Yep.Consider the following function:
int f(char a, float b);
The type of this function is different depending on whether it is an ordinary function or a non-static member function of some class:Its type is “int ()(char,float)” if an ordinary function
Its type is “int (Fred::)(char,float)” if a non-static member function of class Fred
Note: if it’s a static member function of class Fred, its type is the same as if it were an ordinary function: “int (*)(char,float)”.Separately:
Yes, you need an instance.
Yes, that's kind of a different issue, in that it's not going to work anyway for the OP. But I was concentrating on the compiler error message.
@JonB So How to implement the interrupt handler for any i2c device using qt ?
-
@JonB So How to implement the interrupt handler for any i2c device using qt ?
@Qt-embedded-developer Use a normal function as interrupt handler, not a method in a class. In that function you can then call methods of your class if you need to do so.