2011-11-13 25 views
3

我想製作一個程序,將QPlainTextEdit的每一行都發送到WebView,它將加載這些URL。我並不需要檢查的URL,因爲該系統使得它像如何在Qt中讀取QPlainTextEdit的每一行?

http://someurl.com/ + each line of the QPlainTextEdit 

我有一些想法,我不知道如何使用:

  1. 使用foreach循環,這將使其自我等待5秒鐘,以循環再
  2. 做一個QTimer等待像5秒,並帶有整數打勾當整數打線的數量將停止

而所有這一切將在完成每隔4小時用另一個計時器等待。

+0

「我想製作一個程序,我把QPlainTextEdit的每一行都發送到一個WebView,它將加載這些URL。」你不會看我輸入的內容 – user1044359

回答

6

首先你需要QPlainTextEdit的內容。獲取它們並使用新行分隔符分割它們以獲得每個代表一行的QStrings的列表。

QString plainTextEditContents = ui->plainTextEdit->toPlainText() 
QStringList lines = plainTextEditContents.split("\n"); 

處理線的最簡單方法是使用QTimer並存儲在某處列表中的當前索引。

// Start the timer 
QTimer *timer = new QTimer(this); 
connect(timer, SIGNAL(timeout()), this, SLOT(processLine())); 
timer->start(5000); 

現在只要定時器被觸發就調用槽。它只是獲得目前的線路,你可以隨心所欲地做到這一點。

void processLine(){ 
    // This is the current index in the string list. If we have reached the end 
    // then we stop the timer. 
    currentIndex ++; 

    if (currentIndex == lines.count()) 
    { 
     timer.stop(); 
     currentIndex = 0; 
     return; 
    } 

    QString currentLine = lines[currentIndex]; 
    doSomethingWithTheLine(currentLine); 
} 

與4h計時器類似。

+0

Thank You Very Much – user1044359