Solved Console app simple probleme
-
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 ?
-
This is all correct, try re-building your project
-
@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.. -
@LeLev use a debugger, place a breakpoint in the ctor.
we had several people that had qDebug output problems.
-
@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 withqDebug()
, try placing a breakpoint in the constructor. -
Try
SftpClient *client = new SftpClient();
. It should make no difference, but again just in case...
-
-
@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)?
-
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
-
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