[SOLVED] No matching function call ... but function is not called in my code



  • Hi all,
    I have a problem in my code - and it is either something I am overlooking after having looked at it a 1000 times, or ... something different :-)

    The error message is:
    @..\project\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
    ..\project\mainwindow.cpp:16:26: error: no matching function for call to 'TimeSeries::TimeSeries()'
    ui(new Ui::MainWindow)@

    So that is a very basic error message that everyone knows - the thing is that I do not call this constructor at all in the code section in question. The constructor to my TimeSeries class had no parameter before and I added a QString afterwards, which is when the error message showed up.
    If course I have searched all project code for calls to the constructor and checked that they all have the parameter passed.
    The fact that the error occurs in the MainWindow constructor led me to the idea that it might be something Qt-specific (moc et al.), however cleaning and rebuilding, as well as deleting and re-adding a signal&slot did not help (there is a function connected to a button that is called DrawTimeSeries()",i.e. a part of its name is the same as the class constructor - I even renamed that one, you never know :-) ).

    Is there something very obvious that I am overlooking?



  • Hmm,
    The ui(new Ui::MainWindow) is created by converting a QtDesigner form to code. There should also be a ui_Mainwindow.h file in your build directory. So somehow you messed up your MainWindow and the MainWindow QtDesigner class. The compiler is unable to find the ui_MainWindow.h file where the constructor of your form class is.
    Greetz



  • I suspected something like that - but what is the solution? As I wrote, I already cleaned and rebuilt - and I also deleted my build directory, i.e. the file has been recreated. If I remove the parameter from the constructor again the code compiles without a problem. So the MainWindow and the QTDesigner classes shoud be okay.



  • Did you remove the
    @
    namespace Ui {
    class MainWindow;
    }
    @
    Above your MainWindow class declaration (header file) and check that in the ui_Mainwindow.h this is at the end of the file:
    @
    namespace Ui {
    class MainWindow: public Ui_MainWindow {};
    } // namespace Ui
    @
    Then you should be done. The last part in the ui_Mainwindow is the definition and declaration of your constructor ui_Mainwindow class.

    Without the namespace the Ui identifier doesn't tell the compiler where to find the declarations.



  • Dear Jeroen,
    thanks, yes, the code looks exactly like that, so it seems to be not corrupted.

    I have removed the parameter from the constructor and now it works again, so I can proceed with development for the time being, however, this is only a workaround since I need that parameter there :-)



  • Ok, problem solved :-)

    In fact the constructor was nowhere called explicitly in the code without parameters; however, I had an instance of this class as a member of the MainWindow class - and not as a pointer to a TimeSeries object, so of course this instance is created on the stack upon creation of the MainWindow object, and here no parameters were given indeed.

    Thanks for your efforts, Jeroen!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.