Can no longer build due to no matching function.



  • My Qt project has been running fine, and all the code was working. However I realised I had added an incorrect UI file as I needed one with a menu bar. I deleted the original UI file and replaced it. My code however was still somehow calling the original UI file. I cleaned the project and ran QMake on it, as well as retyping the code to call it and still had no luck. The project complied but it didn't use the right file and I had no idea where it was getting the old one from.

    I then took the user files out of the folder to see if that would force it to rebuild and rescan all the files. All that did however was give me an error. I removed the new user files and put the old ones back in and now it just throw up the error:

    • no matching function for call to 'Ui::behindlogin::setupUi(behindlogin* const)'

    and it can't compile. I need to hand the first version of my project in on Friday and I can't even get it to run anymore!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you delete the ui file + the corresponding header and source files ? Did you change any name in between ?



  • Thanks for the reply, I deleted the UI file only. I kept the headers from the old file but when I replaced the file I kept all the names the same. I also deleted the call code for the UI file and retyped it.


  • Lifetime Qt Champion

    Then, since you're in a hurry, the quick way: move these files out of the source tree, recreate your widget, copy back your custom code if you had any



  • @SGaist Is it fine to copy the GUI as well or should I remake that? As in all my labels and edits etc.


  • Lifetime Qt Champion

    You can copy it, just check that all names are correct



  • @SGaist So, I just copied over all the code to a completely new project in a new folder and Qt is still throwing me the same error as in the original post.


  • Lifetime Qt Champion

    Don't overwrite the new files with the content of the old one, just cherry-pick the modifications you made e.g. slot added etc.



  • @SGaist Right, I only copied the code from the old slots directly into the ones in the new project made by Qt, still getting the same error.


  • Lifetime Qt Champion

    So, recreating your widget from scratch in a new project and just copying the slot code gives you the same error ?



  • @SGaist Yup, new folder, new project I created all new files in Qt added all my GUI back, followed to slot, then copied the code in and still get the same error


  • Lifetime Qt Champion

    Did you check that all names were matching ? Ui widget name vs C++ widget name ?



  • @SGaist Right, sorry to be causing so many problems, but thank you for the help! Everything is working now, I missed some of the includes, however I can't use .setModal(true); on a new window opening because it's saying the class has no member called setModal

                behindlogin behindlogin;
                behindlogin.setModal(true);
                behindlogin.exec();
                connClose();

  • Lifetime Qt Champion

    You're welcome !

    setModal and exec are methods from QDialog. From what I understood you have a QMainWindow, no ?



  • @SGaist Ahh yes, I've changed from a Dialog to a MainWindow as I wanted the menu bar at the top.


  • Lifetime Qt Champion

    So problem solved ? :)



  • @SGaist The code actually compiles now! Thank you, the only issue left is I've replaced the code with

                behindlogin behindlogin;
                behindlogin.show();
                connClose();
    
    
    Which causes the window to open and them immediately close after

  • Lifetime Qt Champion

    If you have something like:

    {
        behindlogin behindlogin;
        behindlogin.show();
        connClose();
    } <- behindlogin is destroyed here
    


  • @SGaist Right, so I've replaced it with

                    behindlogin *behindLogin;
    

    in the header file and then

                behindLogin =new behindlogin(this);
                behindLogin->show();
    

    in the main cpp file but it's saying that behindlogin does not name a type?


  • Lifetime Qt Champion

    Is behindlogin a member variable of a class ?



  • @SGaist Uh, honestly I'm not sure.. I'm very new to Qt and I've been following tutorials. Everything I've looked at makes it look like this should work but I can't figure out what I'm doing incorrectly.


  • Moderators

    Hi,

    @dejarked said:

    in the main cpp file but it's saying that behindlogin does not name a type?

    That means you forgot to #include the header that defines the behindlogin.

    @dejarked said:

    @SGaist Uh, honestly I'm not sure.. I'm very new to Qt and I've been following tutorials. Everything I've looked at makes it look like this should work but I can't figure out what I'm doing incorrectly.

    Is your code exactly the same as what's in the tutorial?



  • @JKSH Hey, it is exactly the same as it is in the tutorial and the header file was the first thing I checked, behindlogin.h is included in my mainwindow.h which is where I'm trying to declare it.


  • Moderators

    @dejarked said:

    @JKSH Hey, it is exactly the same as it is in the tutorial and the header file was the first thing I checked, behindlogin.h is included in my mainwindow.h which is where I'm trying to declare it.

    Can you post:

    1. The contents of your .pro file
    2. The contents of behindlogin.h
    3. The contents of mainwindow.h ?


  • Pro:

    #
    # Project created by QtCreator 2015-03-25T23:10:30
    #
    #-------------------------------------------------
    
    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = project
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp \
        behindlogin.cpp \
        offlinebehind.cpp \
        savingwindow.cpp
    
    HEADERS  += mainwindow.h \
        behindlogin.h \
        offlinebehind.h \
        savingwindow.h
    
    FORMS    += mainwindow.ui \
        behindlogin.ui \
        offlinebehind.ui \
        savingwindow.ui
    

    behindlogin.h

    #ifndef BEHINDLOGIN_H
    #define BEHINDLOGIN_H
    
    #include <QMainWindow>
    #include "mainwindow.h"
    
    namespace Ui {
    class behindlogin;
    }
    
    class behindlogin : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit behindlogin(QWidget *parent = 0);
        ~behindlogin();
    
    private slots:
        void on_actionExit_triggered();
    
        void on_actionNew_Data_triggered();
    
    private:
        Ui::behindlogin *ui;
    };
    
    #endif // BEHINDLOGIN_H
    

    mainwindow.h:

    
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include "behindlogin.h"
    #include <QMainWindow>
    #include <QtSql>
    #include <QtDebug>
    #include <QFileInfo>
    
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        QSqlDatabase mydb;
        void  connClose(){
            mydb.close();
            mydb.removeDatabase(QSqlDatabase::defaultConnection);
        }
    
        bool connOpen()
        {
    
            mydb=QSqlDatabase::addDatabase("QSQLITE");
            mydb.setDatabaseName("C:/Users/Jack/Desktop/ProjNEW/SQlite/dataset.db.sqlite");
    
            if(!mydb.open()){
               qDebug()<<("Disconnected..");
               return false;
            }
            else{
                qDebug()<<("Connected..");
                return true;
               }
    
        }
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private slots:
    
        void on_LoginButton_clicked();
    
        void on_actionOpen_triggered();
    
        void on_actionExit_triggered();
    
    private:
        Ui::MainWindow *ui;
        behindlogin *behindLogin;
    };
    
    #endif // MAINWINDOW_H

  • Moderators

    Hmm... I can't see any mistakes in the code.

    What's the full error message? Which line in which file is the error in?



  • @JKSH The full message is:

    In file included from /behindlogin.h
    from behindlogin.cpp
    behindlogin does not name a type.

    and the line of code it's flagging is:

    
        behindlogin *behindLogin;

  • Lifetime Qt Champion

    Circular dependencies !

    You are including mainwindow.h in behinglogin.h and behindlogin.h in mainwindow.h.

    You can remove both includes: in behindlogin.h because you don't use it at all and in mainwindow.h because you can use forward declarations when declaring pointer data members. That also helps avoid including many headers to use your class.



  • @SGaist Ahhh thank you so much! It's all sorted now, I've added my final bits of code and no more errors!

    Thanks @SGaist for all the help and thank you @JKSH as well!


  • Lifetime Qt Champion

    Good !

    You're welcome !

    Don't forget to mark the thread as [solved] so other forum users may know a solution has been found :)


Log in to reply
 

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