亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4121 | 回復(fù): 0
打印 上一主題 下一主題

[求助]qt多線程繪制曲線出錯(cuò) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2008-10-24 15:05 |只看該作者 |倒序?yàn)g覽
小弟剛學(xué)qt多線程編程不久,寫了一個(gè)多線程的程序,希望能有兩個(gè)線程分別負(fù)責(zé)兩個(gè)繪制曲線的操作,這兩個(gè)操作由按鈕觸發(fā),程序如下,但是編譯能通過,運(yùn)行卻會(huì)報(bào)如下錯(cuò)誤:
段錯(cuò)誤:setPen will be reset by begin()
不知如何修改,還望各位大大能指點(diǎn)一二,感激不盡~
#ifndef TEST_H
#define TEST_H

#include <qdialog.h>
#include <qdatetime.h>
#include <qpainter.h>
#include <qstring.h>
#include <qthread.h>

class QPushButton;
class Draw;

class ThreadA : public QThread
{
public:
    ThreadA();

    void run();
   
private:
    bool stopped;
};

class ThreadB : public QThread
{
public:
  ThreadB();

  void run();

private:
  bool stopped;
};

class Draw : public QDialog
{
    Q_OBJECT
public:
    Draw(QWidget* parent = 0, const char* name = 0);

private:   
    QPushButton* buttonA;
    QPushButton* buttonB;
    QPushButton* button1;
    ThreadA threadA;
    ThreadB threadB;
   
protected:   
   
public slots:
    void drawGrid();
    void startA();
    void startB();
   
protected slots:
    void languageChange();
};
#endif //TEST_H


#include "test.h"

#include <qdialog.h>
#include <qpushbutton.h>
#include <qpainter.h>
#include <qrect.h>

ThreadA::ThreadA()
{
    stopped = false;
}

void ThreadA::run()                         //根據(jù)數(shù)組里的點(diǎn)繪制線
{
  int a[6] = {60, 84, 50, 91, 84, 101};
  pa = new QPainter();
  pa->setPen(red);
  int i = 0;
    while(!stopped)
    {
      pa->drawLine(a, a[i + 1], a[i + 2], a[i + 3]);
      sleep(1);
      i = i + 2;
      if (i == 4)
        stopped = true;
    }
  pa->end();
}

ThreadB::ThreadB()
{
    stopped = false;
}

void ThreadB::run()                        
{
  int b[6] = {63, 207, 92, 121, 65, 214};
  pb = new QPainter();
  pb->setPen(blue);
  int i = 0;
    while(!stopped)
    {
      pb->drawLine(b, b[i + 1], b[i + 2], b[i + 3]);
      sleep(1);
      i = i + 2;
      if (i == 4)
        stopped = true;
    }
  pb->end();
}

Draw :: Draw(QWidget* parent, const char* name) : QDialog(parent, name)
{
    if (!name)
      setName("draw");
    QPalette pal;
    QColorGroup cg;
    cg.setColor( QColorGroup::Background, QColor( 154, 230, 230) );
    cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
    cg.setColor( QColorGroup::ButtonText, black );
    pal.setActive( cg );
    setPalette( pal );

    buttonA = new QPushButton(this, "buttonA");
    buttonA->setGeometry(5, 5, 80, 30);

    buttonB = new QPushButton(this, "buttonB");
    buttonB->setGeometry(5, 40, 80, 30);

    button1 = new QPushButton(this, "button1");
    button1->setGeometry(90, 5, 80, 30);

    connect(buttonA, SIGNAL(clicked()), this, SLOT(startA()));
    connect(buttonB, SIGNAL(clicked()), this, SLOT(startB()));
    connect(button1, SIGNAL(clicked()), this, SLOT(drawGrid()));
    languageChange();
    resize(QSize(240, 320));
}

void Draw::drawGrid()                    //繪制背景網(wǎng)格
{
    QPainter* painter = new QPainter(this);
    QRect rect(10, 40, 200, 230);
   
    for (int i = 0; i <= 5; i++){
       int x = rect.left() + (i * (rect.width() - 1) / 5);
       double label = 15 * i;
       painter->setPen(black);
       painter->drawLine(x, rect.top(), x, rect.bottom());
       painter->drawLine(x, rect.bottom(), x, rect.bottom() + 5);
       painter->setPen(yellow);
       painter->drawText(x - 10, rect.bottom() + 5, 20, 20, AlignHCenter | AlignTop, QString::number(label));
   }
    painter->setPen(black);   
    painter->drawRect(rect);
}

void Draw::startA()
{
    threadA.start();
    threadA.wait();
}

void Draw::startB()
{
    threadB.start();
    threadB.wait();
}

void Draw::languageChange()
{
    setCaption("It's a test");
    buttonA->setText(tr("startA"));
    buttonB->setText(tr("startB"));
    button1->setText(tr("axis"));
}
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP