2015-12-08 69 views
0

我正在嘗試學習C++ OOP,並認爲它會嘗試一個使用Qt Creator的簡單示例。我點擊了新建項目>項目>應用程序> Qt控制檯應用程序沒有輸出到控制檯?

然後我添加了一個新類test.cpp。 test.cpp和main.cpp都位於Sources文件夾中,test.h位於Headers文件夾中。

這裏是test.h

#ifndef TEST_H 
#define TEST_H 


class test 
{ 
public: 
    test(); 
}; 

#endif // TEST_H 

TEST.CPP

#include "test.h" 
#include "iostream" 

using namespace std; 

test::test() 
{ 
    cout<<"Inside test's constructor "<<endl; 
} 

的main.cpp

#include "iostream" 
#include "test.h" 

using namespace std; 

int main() 
{ 

    test ts; 

    return 0; 
} 

當我點擊運行按鈕,它的建成並運行。控制檯窗口顯示,但「內部測試的構造函數」永遠不會被打印到屏幕上。我究竟做錯了什麼?

+0

最有可能的,它只是關閉太快之前,你可以看到輸出。嘗試從已打開的控制檯窗口運行可執行文件。 – SergeyA

+0

控制檯窗口保持打開狀態,我必須通過Ctrl + C或單擊x按鈕將其關閉。 – WhatIf

+0

這是問題嗎? [運行我的C++代碼給了我一個空白cmd](http://stackoverflow.com/questions/33690697/running-my-c-code-gives-me-a-blank-cmd) –

回答

0

轉到Qt Creator中的首選項,選擇環境。您將在常規選項卡下看到兩個框。它們是用戶界面和系統。

系統下,你會看到

終端:

雷說

在/ usr/X11 /斌/ xterm的-e

嘗試從你現在有一個不同的終端。一段時間以來,這在一些系統上一直是個問題。

0

我停下來理會與cout,控制檯處理等,並只使用QDebug

qDebug() << "Date:" << QDate::currentDate(); 
qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40); 
qDebug() << "Custom coordinate type:" << coordinate; 

#include "test.h" 
#include "iostream" 
#include <QDebug> 

using namespace std; 

test::test() 
{ 
    qDebug()<<"Inside test's constructor "; 
}