Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

QT newbie.. problem sa klasom

[es] :: C/C++ programiranje :: C/C++ za početnike :: QT newbie.. problem sa klasom

[ Pregleda: 1525 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

misk0
.: Lugano :. _.: CH :.

SuperModerator
Član broj: 634
Poruke: 2824
*.adsl.ticino.com.

ICQ: 46802502


+49 Profil

icon QT newbie.. problem sa klasom20.06.2011. u 22:27 - pre 155 meseci
Za fax trebam napraviti neki programcic u C++ koristeci QT. Zasto, kako .. nije se mene pitalo.
Uglavnom imam problem:


SingleThread class:

Code:

#include <QThread>
#include "pthread.h"

#ifndef SINGLETHREAD_H
#define SINGLETHREAD_H

class SingleThread : public QThread
 {
     Q_OBJECT;

 public:
    SingleThread();
    void stopThread();
    void changePriority(int);

 protected:
     void run();

 signals:
     void updateProgress(int);

 private:
     int counter, direction;
     bool working;
     struct sched_param params;

 };
#endif // SINGLETHREAD_H


Code:

#include "SingleThread.h"
#include <stdio.h>
#include <iostream>

SingleThread::SingleThread()
{
    counter = 0;
    working = true;
    direction = 1;
    int policy, s;

    s = pthread_getschedparam(pthread_self(), &policy, &params );
    qDebug("Read success = %d   |   policy: %d | sched_priority: %d", s, policy, params.sched_priority);
    params.sched_priority = 1;

    s = pthread_setschedparam(pthread_self(), SCHED_RR, &params );

    qDebug("Set success: %d | sched_priority: %d", s, params.sched_priority);
    qDebug("Pointer Address: %p \n\n", &params);
};

void SingleThread::run()
{

    working = true;

    std::cout << "Thread::run()" << std::endl;
    while (working){
        counter += direction;
        emit updateProgress(counter);
        msleep(30);
        if ( counter > 99)
        {
            direction = -1;
        } else if ( counter < 1)
        {
            direction = 1;
        }
    }

};

void SingleThread::stopThread() {
    working = false;
}

void SingleThread::changePriority(int newPriority) {
    int policy,s ;
    params.sched_priority = newPriority;

    s = pthread_setschedparam(pthread_self(), SCHED_RR, &params );
    qDebug("Set success: %d \n", s);

    pthread_getschedparam(pthread_self(), &policy, &params );
    qDebug("Policy: %d == Priority: %d\n", policy, params.sched_priority);

}


mainwindow.h
Code:

private:
    SingleThread thread_1, thread_2, thread_3, thread_4, thread_5;


tu deklarishem ove thread-ove i koliko kontam automatski po inicijalizaciji mainwindow-a threadovi su kreirani i pozvan je konstruktor metod thread.

Po startovanju app dobijam ovaj output
Citat:

root@ubuntu-vm:/home/misk0/qt/Test1# sudo ./Test1
Read success = 0 | policy: 0 | sched_priority: 0
Set success: 0 | sched_priority: 1
Pointer Address: 0xbfd49794


Read success = 0 | policy: 2 | sched_priority: 1
Set success: 0 | sched_priority: 1
Pointer Address: 0xbfd497ac


Read success = 0 | policy: 2 | sched_priority: 1
Set success: 0 | sched_priority: 1
Pointer Address: 0xbfd497c4


Read success = 0 | policy: 2 | sched_priority: 1
Set success: 0 | sched_priority: 1
Pointer Address: 0xbfd497dc


Read success = 0 | policy: 2 | sched_priority: 1
Set success: 0 | sched_priority: 1
Pointer Address: 0xbfd497f4



Primjetite da prvi kreiran thread ima policy: 0 i sched_priority 0 a svi ostali imaju druge vrijednosti.
Ne kontam zasto i kako? Imam osjecaj da je neka varijabla djeljena izmedju instanci thread-ova ali ne mogu skontati koja..

hvalaa
:: Nemoj se svadjati sa budalom, ljudi cesto nece primjetiti razliku ::
 
Odgovor na temu

[es] :: C/C++ programiranje :: C/C++ za početnike :: QT newbie.. problem sa klasom

[ Pregleda: 1525 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.