Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject::connect: No such slot error

QObject::connect: No such slot error

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 6 Posters 19.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #13

    Likely that you are opening your application several times.

    Also, you're not destroying your MainWindow object properly.

    I don't see why you need to use a static variable for your vector.

    Also, you should take a look at the documentation of the class you are using, you are reimplementing by hand a method that already exists in QVector. See contains.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • tomyT Offline
      tomyT Offline
      tomy
      wrote on last edited by
      #14

      @SGaist

      Also, you should take a look at the documentation of the class you are using, you are reimplementing by hand a method that already exists in QVector. See contains.

      Thanks, good method. I used it.

      Likely that you are opening your application several times.

      Also, you're not destroying your MainWindow object properly.

      I don't see why you need to use a static variable for your vector.

      I think the issue belongs to running the program by double clicking, so that a double click runs the program and opens a file and the next double click runs the program once again and opens that file again and so on.
      I declared the vector static so that there is only one vector for any execution.

      Incidentally, the program uses the statements:

      MainWindow* mainWin = new MainWindow;  
      mainWin->show();
      

      two times in main.cpp and newFile():

      #include <QApplication>
      #include <QSplashScreen>
      #include "mainwindow.h"
      
      int main(int argc, char* argv[])
      {
         QApplication app(argc, argv);
      
         QSplashScreen* splash = new QSplashScreen;
         splash->setPixmap(QPixmap(":/images/splash.jpg"));
         splash->show();
      
         Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
         splash->showMessage(QObject::tr("Setting up the main window..."),
         topRight, Qt::white);
      
          MainWindow* mainWin = new MainWindow;
      
          if(argc > 1)
              mainWin->loadFile(argv[1]);
      
          mainWin->show();
          splash->finish(mainWin);
          delete splash;
      
          return app.exec();
      }
      
      void MainWindow::newFile()
      {
          MainWindow* mainWin = new MainWindow;
          mainWin->show();
      }
      

      Also, for destroying the objects when closed, I use, setAttribute(Qt::WA_DeleteOnClose); in the Mainwindow's constructor.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #15

        Then if you don't want that to happen, then you have to ensure that there's only one instance of your application running using for example the QtSingleApplication class.

        Why use a new MainWindow for every document ? The editor itself should rather be a dedicated widget.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        tomyT 1 Reply Last reply
        0
        • SGaistS SGaist

          Then if you don't want that to happen, then you have to ensure that there's only one instance of your application running using for example the QtSingleApplication class.

          Why use a new MainWindow for every document ? The editor itself should rather be a dedicated widget.

          tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by tomy
          #16

          @SGaist

          Then if you don't want that to happen, then you have to ensure that there's only one instance of your application running using for example the QtSingleApplication class.

          Does it mean that the user will have only one file opened at the same time? The user may need to open various files and compare, say, the data of two of them at the same time.

          Why use a new MainWindow for every document ?

          Do you mean new MainWindow in newFile() slot or main?
          Please take a look at the explanations of the book about these:
          https://www.imageupload.co.uk/images/2017/09/12/131a64.png
          https://www.imageupload.co.uk/images/2017/09/12/25f435.png
          https://www.imageupload.co.uk/images/2017/09/12/3.png
          https://www.imageupload.co.uk/images/2017/09/12/4.png

          The book has meant an SDI, and for that it has suggested a foreach loop. I didn't understand that loop well and couldn't use it so went for employing a vector.

          I'm still rather astonished by this behaviour:
          The double click sends the name of the file to the loadFile slot so if it's previously opened, the first if statement closes the function and the program execution doesn't reach the function spreadsheet->readFile(fileName) and the file shouldn't open once again, but in effect, it opens again. Isn't it strange?

          The editor itself should rather be a dedicated widget.

          Editor?

          (Sorry For the Delay)

          1 Reply Last reply
          0
          • BjornWB Offline
            BjornWB Offline
            BjornW
            wrote on last edited by
            #17

            @tomy said in QObject::connect: No such slot error:

            connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(close()));
            connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(remove_File(curefile)));

            As always in threads related to signals/slots, I must jump in to advocate the Qt5 syntax:

            connect(closeAction, &QAction::triggered, this, &MainWindow::close);   
            

            because compile time connection checks are awesome :-)

            6thC6 1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #18

              No, I mean having one instance of your application handling more than one file.

              What book is that ?

              No it's not strange, you are expecting your static variable to be the same across all instances of your application, that's wrong.

              The editor: the widget used to edit your document.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              tomyT 1 Reply Last reply
              0
              • BjornWB BjornW

                @tomy said in QObject::connect: No such slot error:

                connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(close()));
                connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(remove_File(curefile)));

                As always in threads related to signals/slots, I must jump in to advocate the Qt5 syntax:

                connect(closeAction, &QAction::triggered, this, &MainWindow::close);   
                

                because compile time connection checks are awesome :-)

                6thC6 Offline
                6thC6 Offline
                6thC
                wrote on last edited by
                #19

                @BjornW I'm with you - you can also hit F2 in the IDE and jump straight to a signal definition or slot implementation... so much win with QObject member connections.

                1 Reply Last reply
                1
                • SGaistS SGaist

                  No, I mean having one instance of your application handling more than one file.

                  What book is that ?

                  No it's not strange, you are expecting your static variable to be the same across all instances of your application, that's wrong.

                  The editor: the widget used to edit your document.

                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by
                  #20

                  @SGaist

                  No, I mean having one instance of your application handling more than one file.

                  It's likely the best choice. If I'm right I think it's related to MDI (Multiple Document Interface) which is what the book pointed to alongside that foreach loop, that I didn't understand well and not sure where, in what functions in the project, to write that loop.

                  What book is that ?

                  C++-GUI-Programming-with-Qt-4-2nd Edition

                  No it's not strange, you are expecting your static variable to be the same across all instances of your application, that's wrong.

                  The static variable is the same between instances of the application if we've created new instances using the menus and buttons. But each time we open new files using double clicking the event is different and it's as though we are executing the app for the first time. Disagree?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #21

                    You are mixing "instance of an application" with "instance of an object in an application".

                    See the documentation about static.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    tomyT 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      You are mixing "instance of an application" with "instance of an object in an application".

                      See the documentation about static.

                      tomyT Offline
                      tomyT Offline
                      tomy
                      wrote on last edited by
                      #22

                      @SGaist said in

                      You are mixing "instance of an application" with "instance of an object in an application".

                      The main class of the project is MainWindow. We create an instance of the class (an object using new) in tow functions, main() and newFile(). So when we run the program by the IDE or its icon (when installed) and manipulate the data, save it, open a file by the Open button, or make a new file by the New button, we have one instance of the application but may have two or more instances of the class. So in these cases our static data member is the same.
                      But when we run our program using a double click on a stored file, we have an instance of the program, and if we open another, again by a double click, we have another instance of the program and these two are as two whole and independent instances and are "not" connected together so that the static data member is the same. And that's why we can open the same file as many times as we wish using double clicking. I think you agree now.

                      My assumption: we can't prevent this unwanted event by manipulating the code of the program unless that manipulation is regarding the operating system to gain assistance from it to tell us if there is a file running at the time being and we decide not to open it again.

                      J.HilkJ 1 Reply Last reply
                      0
                      • tomyT tomy

                        @SGaist said in

                        You are mixing "instance of an application" with "instance of an object in an application".

                        The main class of the project is MainWindow. We create an instance of the class (an object using new) in tow functions, main() and newFile(). So when we run the program by the IDE or its icon (when installed) and manipulate the data, save it, open a file by the Open button, or make a new file by the New button, we have one instance of the application but may have two or more instances of the class. So in these cases our static data member is the same.
                        But when we run our program using a double click on a stored file, we have an instance of the program, and if we open another, again by a double click, we have another instance of the program and these two are as two whole and independent instances and are "not" connected together so that the static data member is the same. And that's why we can open the same file as many times as we wish using double clicking. I think you agree now.

                        My assumption: we can't prevent this unwanted event by manipulating the code of the program unless that manipulation is regarding the operating system to gain assistance from it to tell us if there is a file running at the time being and we decide not to open it again.

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #23

                        @tomy In that case I would suggest something like QSharedMemory.

                        Check in your Main.cpp if an other instance of your programm is already up and running. If it is, pass the File path to your other instance and exit main.


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved