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. Console app simple probleme
Forum Updated to NodeBB v4.3 + New Features

Console app simple probleme

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 6 Posters 992 Views 1 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #1

    Hi,
    I'm trying to instantiate a Q_Object derived object in my console application..

    #include <QCoreApplication>
    #include "sftpclient.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        SftpClient client;
        client.sftp_createFile("testFile.txt","file content");
        return a.exec();
    }
    

    I instantiate an SftpClient witch is a Q_Object

    class SftpClient : public QObject
    {
        Q_OBJECT
    public:
        explicit SftpClient(QObject *parent = nullptr);
    signals:
        void sftp_createFile_error(QString err);
    public slots:
      
        int sftp_deleteFile(QString f);
        void sftp_connect();
         };
    
    #endif // SFTPCLIENT_H
    
    //SftpClients constructor
    SftpClient::SftpClient(QObject *parent) : QObject(parent)
    {
        qDebug()<<"creating the client..."; // never executed
         sftp_connect();//
    }
    
    

    It looks like my SftpClients constructor is never called.. Can someone tell me why ?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      This is all correct, try re-building your project

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ODБOïO 1 Reply Last reply
      3
      • VRoninV VRonin

        This is all correct, try re-building your project

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @VRonin hi,
        I did. But nothing changes. I read this article : http://treyweaver.blogspot.fr/2013/02/qt-console-application-template-tutorial.html and tested the exemple but this is still not working..

        aha_1980A JonBJ 2 Replies Last reply
        0
        • ODБOïO ODБOï

          @VRonin hi,
          I did. But nothing changes. I read this article : http://treyweaver.blogspot.fr/2013/02/qt-console-application-template-tutorial.html and tested the exemple but this is still not working..

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @LeLev use a debugger, place a breakpoint in the ctor.

          we had several people that had qDebug output problems.

          Qt has to stay free or it will die.

          1 Reply Last reply
          4
          • ODБOïO ODБOï

            @VRonin hi,
            I did. But nothing changes. I read this article : http://treyweaver.blogspot.fr/2013/02/qt-console-application-template-tutorial.html and tested the exemple but this is still not working..

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @LeLev
            Try one of the following:

            • Your constructor should be called for line SftpClient client;. Just in case that is happening real early and there is a problem with qDebug(), try placing a breakpoint in the constructor.

            • Try SftpClient *client = new SftpClient();. It should make no difference, but again just in case...

            1 Reply Last reply
            1
            • M Offline
              M Offline
              Morix Dev
              wrote on last edited by Morix Dev
              #6

              @LeLev : I've just tried just copy/pasting your code into a blank console application in my QtCreator and everything works perfectly fine!

              The constructor is getting called, as expected.

              Are you sure that you have qmake-ed and rebuilt the project? Maybe you can try to completely delete your build folder and rebuild everything from scratch (maybe some temporary or moc/obj files causing problems)?

              /Morix

              1 Reply Last reply
              2
              • BuckwheatB Offline
                BuckwheatB Offline
                Buckwheat
                wrote on last edited by
                #7

                Hi @LeLev ,

                I am unsure what your end goal is here. There is a lot missing from your code for us to check what could be wrong. What signals are you monitoring? What does sftp_connect actually do?

                Have a look at QNetworkAccessManager http://doc.qt.io/qt-5/qnetworkaccessmanager.html for complete information. Sure beats writing your own ;D

                Dave Fileccia

                ODБOïO 1 Reply Last reply
                0
                • BuckwheatB Buckwheat

                  Hi @LeLev ,

                  I am unsure what your end goal is here. There is a lot missing from your code for us to check what could be wrong. What signals are you monitoring? What does sftp_connect actually do?

                  Have a look at QNetworkAccessManager http://doc.qt.io/qt-5/qnetworkaccessmanager.html for complete information. Sure beats writing your own ;D

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #8

                  Thx all for help.
                  @Buckwheat nothing special, i just wanted to create a simple console app and instatiate a Qobject derived object in my main, The only thing should be executed is 'qDebug()<<"creating the client..."

                  @Buckwheat said in Console app simple probleme:

                  What does sftp_connect actually do?

                  Nothing ! because never called

                  I just Re-created the project to ~solve this...

                  Thx

                  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