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. Need help for using qDebug() with Qt plugin for Visual Studio 2008
QtWS25 Last Chance

Need help for using qDebug() with Qt plugin for Visual Studio 2008

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 6.2k Views
  • 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.
  • E Offline
    E Offline
    Ejay
    wrote on last edited by Ejay
    #1

    Hello there, I am trying to use the qDebug(). Here i am sharing a small sample code which i used for File IO in Qt. The code is working well as expected. But upon read or write action i see debug messages on build window. But i want to get them on windows console. I have tried setting the Linker>System>SubSystem : to "Console (/SUBSYSTEM:CONSOLE)". Getting the messages on console is necessary to serve a future purpose

    Environment:

    Windows 8.1

    Visual Studio 2008 SP1 trial with Qt 4.8.4 Plugin

    Platform: Win32

    //qtfileio.h
    
    #ifndef QTFILEIO_H
    #define QTFILEIO_H
    
    #include <QtGui/QWidget>
    #include "ui_qtfileio.h"
    #include <QFile>
    #include <QString>
    #include <QDebug>
    #include <QTextStream>
    #include <QMessageBox>
    
    class QtFileIO : public QWidget
    {
    	Q_OBJECT
    
    public:
    	QtFileIO(QWidget *parent = 0, Qt::WFlags flags = 0);
    	~QtFileIO();
    	void write(QString filename);
    	void read(QString filename);
    
    private:
    	Ui::QtFileIOClass ui;
    
    public slots:
    	void on_btnRead_clicked();
    	void on_btnWrite_clicked();
    };
    
    #endif // QTFILEIO_H
    
    
    //qtfileio.cpp
    
    /*----------------------------------------------------------------------------
     * Author: Eshwar
     * Created on 06 December, 2017, 04:01 PM
     * Description: File IO in Qt
     * Ref. https://youtu.be/tY6nW3Wm3NE
     *----------------------------------------------------------------------------*/
    
    #include "qtfileio.h"
    
    QFile file("./disk.txt");	 // file location as parameter
    QTextStream stream(&file);	 // create text stream variable
    
    QtFileIO::QtFileIO(QWidget *parent, Qt::WFlags flags)
    	: QWidget(parent, flags)
    {
    	ui.setupUi(this);
    }
    
    QtFileIO::~QtFileIO()
    {
    
    }
    
    void QtFileIO::on_btnRead_clicked()
    {
    	if(!file.open(QFile::ReadOnly | QFile::Text))								// read only mode
    		QMessageBox::warning(this,"File error","cannot read file");				// throw error if file not accessible
    
    	QString text = stream.readAll();											// read the plain text
    	ui.plainTextEdit->setPlainText(text);
    	file.close();																// close file
    	
    	qDebug() << "File read";
    }
    
    void QtFileIO::on_btnWrite_clicked()
    {	
    	if(!file.open(QFile::WriteOnly | QFile::Text))								// write only mode
    		QMessageBox::warning(this,"File error","cannot write to file");
    	
    	QString text = ui.plainTextEdit->toPlainText();
    	stream << text;
    	file.flush();																// flush the text data in the file
    	file.close();																// close file
    
    	qDebug() << "File written";
    }
    
    
    //main.cpp
    
    #include "qtfileio.h"
    #include <QtGui/QApplication>
    
    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    	QtFileIO w;
    	w.show();
    	return a.exec();
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Where do you expect to see the output?
      Did you create a console application?

      Visual Studio 2008 SP1 trial with Qt 4.8.4 Plugin

      Nice and modern ;)

      "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

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Ejay
        wrote on last edited by
        #3

        @VRonin This is a GUI application. I just found out that i am getting debug messages on the small output window, the window where you see the build messages. However i want to see these messages on a console. This is necessary because i will be porting the application to Win CE7 where only console is helpful for actual debugging. This is a future embedded system code exercise therefore i have to use these nice and modern things only ;)

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

          Just follow the link I posted above to tell VS you want the console out

          "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

          JonBJ 1 Reply Last reply
          0
          • VRoninV VRonin

            Just follow the link I posted above to tell VS you want the console out

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

            @VRonin / "Lee Van Cleef" :)

            Given that the OP has said "This is a GUI application", how does your link which assumes a console application help him?

            I know nothing about "Win CE7". But it may be that anything written via qDebug() which appears within Visual Studio in its Debug output window will automatically go to whatever Win CE has in the way of a Console window? Has the OP actually just tried existing code under Win CE instead of inside VS? Unless I'm misunderstanding what the OP wishes to achieve....

            VRoninV E 2 Replies Last reply
            0
            • MikhailGM Offline
              MikhailGM Offline
              MikhailG
              wrote on last edited by MikhailG
              #6

              You could go in a hard way. Do you familiar with interprocess communication or anonymous pipes or bi directional pipes? Your GUI app could interact with a small console app and display only that stuff you send via one of those approaches. So basicly you would have a GUI app and a console (for debugging purpose) app and the GUI should start the console.

              E 1 Reply Last reply
              0
              • JonBJ JonB

                @VRonin / "Lee Van Cleef" :)

                Given that the OP has said "This is a GUI application", how does your link which assumes a console application help him?

                I know nothing about "Win CE7". But it may be that anything written via qDebug() which appears within Visual Studio in its Debug output window will automatically go to whatever Win CE has in the way of a Console window? Has the OP actually just tried existing code under Win CE instead of inside VS? Unless I'm misunderstanding what the OP wishes to achieve....

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                @JNBarchan

                I was referring to:

                • Choose Configuration Properties>Linker>System.
                • For the "Subsystem" property in the right-hand pane, click the drop-down box in the right hand column.
                • Choose "Console (/SUBSYSTEM:CONSOLE)"

                Having the console subsytem does not prevent you from creating Qt widgets.

                @MikhailG Possible but It's like using nuclear bombs to get rid of a bird's nest

                "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

                JonBJ 1 Reply Last reply
                0
                • JonBJ JonB

                  @VRonin / "Lee Van Cleef" :)

                  Given that the OP has said "This is a GUI application", how does your link which assumes a console application help him?

                  I know nothing about "Win CE7". But it may be that anything written via qDebug() which appears within Visual Studio in its Debug output window will automatically go to whatever Win CE has in the way of a Console window? Has the OP actually just tried existing code under Win CE instead of inside VS? Unless I'm misunderstanding what the OP wishes to achieve....

                  E Offline
                  E Offline
                  Ejay
                  wrote on last edited by
                  #8

                  @JNBarchan The said code has been ported and tested on required target module running Win CE7.
                  This was done by just changing the right Qt platform.
                  1_1512725782911_Screenshot 2.png 0_1512725782910_Screenshot 1.png

                  1 Reply Last reply
                  0
                  • VRoninV VRonin

                    @JNBarchan

                    I was referring to:

                    • Choose Configuration Properties>Linker>System.
                    • For the "Subsystem" property in the right-hand pane, click the drop-down box in the right hand column.
                    • Choose "Console (/SUBSYSTEM:CONSOLE)"

                    Having the console subsytem does not prevent you from creating Qt widgets.

                    @MikhailG Possible but It's like using nuclear bombs to get rid of a bird's nest

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @VRonin said in Need help for using qDebug() with Qt plugin for Visual Studio 2008:

                    @JNBarchan

                    Having the console subsytem does not prevent you from creating Qt widgets.

                    I was not aware of this. I had thought /SUBSYSTEM:CONSOLE meant no Windows windows at all. I see that it only means create a console as well at startup.

                    However, I note that (Visual Studio at least) has /SUBSYSTEM:WINDOWSCE option. If you need that for your app (I don't know), then you can't have the other....

                    I will say one thing to the OP about this. If you go for /SUBSYSTEM:CONSOLE it means your app will always open a console. If you compile for release, and your qDebug() statements have no effect, you will still get a console. Is that what you want?

                    If not, you have two choices:

                    1. Ensure that you have /SUBSYSTEM:CONSOLE only in the Debug configuration, not the Release configuration.
                    2. Use Windows ::AllocConsole() to allocate a console, dynamically and as needed or not. This may get you round all the other issues.
                    E 1 Reply Last reply
                    0
                    • MikhailGM MikhailG

                      You could go in a hard way. Do you familiar with interprocess communication or anonymous pipes or bi directional pipes? Your GUI app could interact with a small console app and display only that stuff you send via one of those approaches. So basicly you would have a GUI app and a console (for debugging purpose) app and the GUI should start the console.

                      E Offline
                      E Offline
                      Ejay
                      wrote on last edited by
                      #10

                      @MikhailG i have started with Qt about 15 days ago, so i better look for a simpler way to serve the purpose :)

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @VRonin said in Need help for using qDebug() with Qt plugin for Visual Studio 2008:

                        @JNBarchan

                        Having the console subsytem does not prevent you from creating Qt widgets.

                        I was not aware of this. I had thought /SUBSYSTEM:CONSOLE meant no Windows windows at all. I see that it only means create a console as well at startup.

                        However, I note that (Visual Studio at least) has /SUBSYSTEM:WINDOWSCE option. If you need that for your app (I don't know), then you can't have the other....

                        I will say one thing to the OP about this. If you go for /SUBSYSTEM:CONSOLE it means your app will always open a console. If you compile for release, and your qDebug() statements have no effect, you will still get a console. Is that what you want?

                        If not, you have two choices:

                        1. Ensure that you have /SUBSYSTEM:CONSOLE only in the Debug configuration, not the Release configuration.
                        2. Use Windows ::AllocConsole() to allocate a console, dynamically and as needed or not. This may get you round all the other issues.
                        E Offline
                        E Offline
                        Ejay
                        wrote on last edited by Ejay
                        #11

                        @JNBarchan i want the GUI to open up a console and print the debug messages there. In VS the debug messages appear at output window. Similarly while executing by the os i want the console window to show debug messages

                        JonBJ 1 Reply Last reply
                        0
                        • E Ejay

                          @JNBarchan i want the GUI to open up a console and print the debug messages there. In VS the debug messages appear at output window. Similarly while executing by the os i want the console window to show debug messages

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @Ejay

                          Similarly while executing by the os i want the console window to show debug messages

                          @VRonin's of changing the linker option to /SUBSYSTEM:CONSOLE should do this.

                          i want the GUI to open up a console [when running from Visual Studio]

                          Again, the above should do this.

                          In VS the debug messages appear at output window.

                          Yup! Qt's qDebug will, I imagine, go to the "debug window", which VS displays in its Output window. I don't know of/think there is a way to change that behaviour in VS --- at least, not without writing code in "VS extensions" themselves, which is another matter.

                          Your requirement for Visual Studio output of debug lines is "unusual". Unless you/someone else knows better, you may have to settle for the above behaviour while in VS. Does that really matter? If it does, the only other way I can see is for you to cease using qDebug() statements in your code, and use something similar of your own which writes to a "console" explicitly rather than to the debug stream.

                          1 Reply Last reply
                          2

                          • Login

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