0

This is probably a pretty basic question, but it is giving me a problem. I have an FTDI USB3 development board that I want to drive by pressing buttons on a Qt form. The FTDI interface examples are all static functions, so that the generated values can be used elsewhere. Here is what I hoped would work, but pressing the button on the Qt form does not seem to call the FTDI static function (no visible response in the Qt debug). Any suggestions are welcome!

    //Click button on Qt form
    void StarLight::on_pushBtnFind_clicked()
    {
    FT_STATUS displayDevicesMethod2(void);
    QApplication::processEvents();
    }
    // Method 2 for displaying the list of devices connected.
    static FT_STATUS displayDevicesMethod2(void)
   {
    FT_STATUS   ftStatus;
    FT_HANDLE   ftHandle = NULL;

    // Get and display the list of devices connected
    // First call FT_CreateDeviceInfoList to get the number of connected devices.
    // Then call FT_GetDeviceInfoList or FT_GetDeviceInfoDetail to display device info.
    // Device info: Flags (usb speed), device type (600 e.g.), device ID (vendor, product), 
    handle for subsequent data access.
    DWORD numDevs = 0;
    ftStatus = FT_CreateDeviceInfoList(&numDevs);   // Build a list and return number 
    connected.
    if (FT_FAILED(ftStatus))
    {
        printf("Failed to create a device list, status = %lu\n", ftStatus);
    }
    printf("Successfully created a device list.\n\tNumber of connected devices: %lu\n", 
    numDevs);
    // Method 2: using FT_GetDeviceInfoDetail
    if (!FT_FAILED(ftStatus) && numDevs > 0)
    {
        ftHandle = NULL;
        DWORD Flags = 0;
        DWORD Type = 0;
        DWORD ID = 0;
        char SerialNumber[16] = { 0 };
        char Description[32] = { 0 };
        for(DWORD i = 0; i <numDevs; i++)
        {
            ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, NULL, SerialNumber, 
     Description, &ftHandle);
            if (!FT_FAILED(ftStatus))
            {
                printf("Device[%lu] (using FT_GetDeviceInfoDetail)\n", i);
                printf("\tFlags: 0x%lx %s | Type: %lu | ID: 0x%08lX | ftHandle=0x%p\n",
                    Flags,
                    Flags & FT_FLAGS_SUPERSPEED? "[USB 3]":
                    Flags & FT_FLAGS_HISPEED? "[USB 2]":
                    Flags & FT_FLAGS_OPENED? "[OPENED]": "",
                    Type,
                    ID,
                    ftHandle);
                printf("\tSerialNumber=%s\n", SerialNumber);
                printf("\tDescription=%s\n", Description);
            }
          }
        }
      return ftStatus;
    }
Currents
  • 1
  • 1
  • Few questions. Where is your Qt code with `QPushButton::cliked` connection and the call to your static function? Do you want to call this `FT_STATUS displayDevicesMethod2(void)`? How the body of `displayDevicesMethod2` is relevant to the problem? Do you create `QApplication` and call `app.exec();` in your main? Where is your `qDebug` print? – pptaszni Aug 16 '22 at 12:20
  • 2
    This is not a Qt issue but a C++ (syntax) issue, `FT_STATUS displayDevicesMethod2(void);` is not a function call but a function declaration. You're not calling anything so nothing happens :) Try `displayDevicesMethod2();` or `FT_STATUS status = displayDevicesMethod2();` instead. – Fareanor Aug 16 '22 at 12:21
  • Hi Fareanor - thanks for the suggestions, but either option gets a 'Use of undeclared identifier' warning. – Currents Aug 16 '22 at 12:49
  • @Currents Yes, the function definition is written (and seen) after the code block from where you are using it and consequently unknown at the time you call it. You need to, at least, declare it before using it so that the compiler will know that the function exists (or move the definition before where you use it). I think you should properly learn C++ by using a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) of your choice because these are very basic C++ concepts you seem to lack. – Fareanor Aug 16 '22 at 12:56
  • OK - yes, I'm being stupid! Thanks for pointing this out :) – Currents Aug 16 '22 at 13:05

0 Answers0