Using threads

How can I create a thread of class with the header file?

/* * NetworkThread.cpp * *  Created on: 1 Jan 2014 *      Author: krikor */

#include "NetworkThread.hpp"#include #include 

void NetworkThread::run(){     // qDebug() << "hello from worker thread " ;    qDebug() << "checked";

}
#include #include 

 class NetworkThread : public QThread {     Q_OBJECT private:     void run(); };

How can I call a function?

NetworkThread wire;
thread. Start();

thread.getData ():
thread. Wait();

I would like to start a thread as Thøis

There are a few other errors on your code.

Try this in the header

Mamadou wrote:

I'm working on it, but I get the error

/*
 * EventWorker.hpp
 *
 *  Created on: 2 Jan 2014
 *      Author: krikor
 */

#ifndef EVENTWORKER_HPP_
#define EVENTWORKER_HPP_

#include 
#include 

class EventWorker: public QObject {

         Q_OBJECT

public:
    EventWorker();
    virtual ~EventWorker();
public slots:
    void doWork(); //NO CONSTsignals:
    void finishedThread();
};

#endif /* EVENTWORKER_HPP_ */

Tags: BlackBerry Developers

Similar Questions

  • Should swing JFrame - I use threads or JDialogBox (or both!)?

    Hello

    I create a game in which several pieces may be on a site, and when you click on this square, I want a pop up window and allow the user to select from a list of parts.
    The list of the selected pieces would return to the main program when the window is closed. When the window is opened, I would like to suspend the execution of the program.


    So, copy the following code essentially illustrates the basics of my dilemma.
    public class JBegin {
         public static void main(String[] args){
              customFrame newFrame= new customFrame(0);
         }
    }
    (code}
    to import java.awt.Dimension;
    import java.awt.event.MouseEvent;
    java.awt.event.MouseListener import;

    to import javax.swing.JFrame;


    public class customFrame extends JFrame implements {MouseListener
    int x = 0, y = 2, z;
    public customFrame (int layer) {}
    z = + 1 layer.
    addMouseListener (this);
    this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    this.setVisible (true);
    this.setSize (New Dimension (1000, 1000));
    }
    @Override
    {} public void mouseClicked (MouseEvent arg0)
    TODO self-generating method stub
    subset of customFrame = new customFrame (z);
    freeze the previous window
    wait customFrame close
    get the values of subset.
    x = y * 2 + z;
    }

    @Override
    {} public void mouseEntered (MouseEvent arg0)
    TODO self-generating method stub

    }

    @Override
    {} public void mouseExited (MouseEvent arg0)
    TODO self-generating method stub

    }

    @Override
    {} public void mousePressed (MouseEvent arg0)
    TODO self-generating method stub

    }

    @Override
    {} public void mouseReleased (MouseEvent arg0)
    TODO self-generating method stub

    }

    }
    In the customFrame class, after the mouse button has been clicked, I want the code to wait for the new customFrame window to be closed before evaluating the equation.
    
    I've done some reading, and I've heard that JDialog will accomplish most things a JFrame will (Though I haven't been able to find any tutorials on how to paint in JDialog).  I also may be hesitant because I have some classes which are configured wonderfully for a JFrame.
    
    In any case, would threads or a JDialog box be a more appropriate way to solve this problem?  And if it is the JDialog option, do you know of a good JDialog painting tutorial (as, obviously, I've been having trouble finding one)?  
    
    Thanks for all your time and advice                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    Thus, it seems that JDialog is not slow down the progression of the code.

    Yes, he does, that's why I suggested it. Of course he could help if I spelled "modal" OK, if you could watch the API to see what method you use to define a modal dialog box.

    You can also use a JOptionPane, which simply creates a JDialog formatted for you.

    The choice is yours.

  • 'Threading' has started on my incoming emails; How can I remove it?

    I want to see all my emails separately - not 'threaded' together in the subject line. I don't have a clue as to why - after years of use - thread just started a few days ago?

    Sort by view by Unthreaded

  • What is the wheel yellow in the left margin of the subject field of the thread pane?

    Today, some, but not all of the unread mails had a small symbol yellow like the Sun wheel in the left margin of the pane Inbox thread.
    The symbol appears in the same area where the other e-mails can have small arrows indicating that I responded to an email.

    When I click on a such mail, it goes to State reading (normal font as opposed to "BOLD"), and the wheel also goes.

    While trying to ask this question, I had to request a reset password, and after you receive that mail, the last unread message remaining which had this wheel, had more of her. I am therefore unable to make a screenshot showing the symbol. However, it consists of a circular yellow box with a large number of short black lines in the radial direction, places evenly along the perimeter inside the yellow box, forming a ring or radial lines.

    If you know the symbol, what you call it? What he's trying to say?

    In which case it is important, I use an IMAP account.

    Looks like it's the new message indicator when using threads messages.

    List icons.
    http://KB.mozillazine.org/Icons_-_Thunderbird

  • Satellite U400: How to set the BIOS password & learn how to use facial recognition

    I have a Satellite U400 Satellite.

    Can someone direct me to a link of support for the implementation in passwords in BIOS?

    There are several options and I don't know what does what...
    Thanks for your help...

    Another point:

    I feel that the definition of a password or both in the BIOS will help the face recognition program to work, for some reason any.
    I NEVER managed to properly configure that, although I tried several times,
    go in accordance with the instructions.

    A lot of frustration and time, I would say.
    This is for safety.

    > Can someone direct me to a link of support for the implementation in passwords in BIOS?
    If you want to set the password in the BIOS you will need to access the BIOS by pressing the F2 key immediately after that the laptop has been powered.

    There is a 3rd tab security.
    There you can set the BIOS password. You would need to put everything first and then you must confirm the password once more to

    > I have the impression that the definition of a word or two in the BIOS will help the face recognition program to work, for some reason any.
    This s the password of BIOS nonsense has nothing to do with the reorganization of face.

    Here's a very useful thread that provides details on the reorganization of the face:
    http://forums.computers.Toshiba-Europe.com/forums//thread.jspa?MessageID=147434

    Check it out. It is very useful

  • HP Pavilion g6-2298nr: when HP Recovery is not available... the system using Windows 8 as image backup?

    I would like to start with a big shout out to Paul T for his VERY useful thread here!

    http://h30434.www3.HP.com/T5/notebook-operating-systems-and-software/Windows-8-product-key-for-pavil...

    Family of a friend asked me to work on their laptop, because I know more about computers they do... they are people very well, was happy to help out, but true to form, like many PC users, they did not bother keeping the documentation provided with the laptop (HP Pavilion g6-2298nr), or they bother to burn recovery using HP DVD built in recovery software which is comes standard on laptops... If I am interpreting what HP's Web Site had to say about the laptop model HP Pavilion g6-2298nr, correctly, she is the serial number it is no longer eligible for free technical support and I have to pay a fee just to talk to someone and to order recovery of the HP DVD (family friend bought in Dec 2014 so it seems REALLY odd that I wouldn't be able to just order) DVD recovery without having to pay tech support a tax just to ask to order the recovery DVD!  .. But anyway...) ...

    Where was the product key "integrated" in the BIOS really comes in handy!   I crossed my fingers, used the method mentioned in the thread linked above, and it worked!   ... have to admit it was a bit strange at first, do not use the product key sticker like the old days, but I can see how it works better in the long term - helps prevent piracy, you don't have to worry if someone who do not realize the importance of product keys thumbnail it takes off and he throws...

    Unfortunately, it seems that when you reinstall Windows in this way, you lose the HP Backup and Recovery program ... in this case my friend family had the misfortune to pay someone to repair this laptop which has not bothered to tell them "Hey, I replaced the hard drive that goes wrong but if you don't get a laptop cooler for this sucker to the laptop just going to overheat again." ... of course, the money they paid what we call 'tech technician' who went down draining when the laptop fried a second drive hard, or maybe the tech them faced with a bad hard drive, who knows? (technology bought a hard drive OEM off ebay)...

    ... Sorry to sound harsh about this type of technology, I must confess I only worked in the field of PC repair for a few months more than a decade before letting him make a stay-at-home-dad (wife is a pharmacist so I'm lucky enough to be able to stay at home) so my experience is VERY limited compared to other people... but the back then I have always treated my customers the way I would treat a friend , and if it's a friend of you offer advice on the prevention of such problems in the future... this laptop gets HOT like you wouldn't, I seated him on a very reliable laptop cooler (slab thickness of aluminium which does a great job as a radiator with the fans, this one)

    http://www.Newegg.com/product/product.aspx?item=N82E16834953038

    "(and I left my friend's family know in no uncertain terms that they need to order this laptop cooler if they use this laptop...).

    Replace hard drive, I installed seems to work very well, but of course it is not an "official WD hard drive"... when I tried to install the software of cyberdirector photolink for example on the link below, received an error message "this is not a WD hard drive so cannot install this software"...

    http://support.HP.com/us-en/drivers/selfservice/HP-Pavilion-G6-2200-notebook-PC-series/5296082/model...

    that is fine I really don't think my friend family cares about this program... but it makes me wonder, even if I did trust the download at this link below

    http://www.TechSpot.com/downloads/5190-HP-backup-and-Recovery-Manager.html

    If program HP Backup and Recovery manager would work even first because it is not an official hard drive WD (I also ordered a hard drive OEM off ebay .. but does not support the family of my friend for the drive hard because they were good for my munchkins and did not want to pay through the nose for a more expensive hard drive so of course I tried to minimize my own...)... I also think the type of program is based on a "C" and "D" drive is set up as if it were when the laptop comes with the original hard drive and saves a copy of the backup on the disk "D"... I guess I could use disk management to create a different partition, label it "D" and see if HP Backup and Recovery work, but it seems a bit... questionable... not to mention that I feel uncomfortable to download something that is not directly on the HP Web site as an "official"... download

    I know that Windows 8 has a utility of 'image system' built-in that allows you to do exactly that... an image of the system... as I said my friend family is good people, but I'm guessing that sooner or later they're going to screw up this laptop by pulling again as do many users of the computer... it would be nice if I could burn a system image of what is on the laptop now on DVD and hang on, then when they come back to me screaming in the future ' help, laptop does not work yet! I can just restore the system image on DVD instead of having to go through the hassle of reinstalling Windows, graphics/audio/drivers etc., zillion Windows updates and an etc. all over again.

    What I was asking, that is... would this even work?    I have never tried to use the image of the system in a situation like this with the product being key ' built in ' BIOS, this kind of thing is brand new to... worth me burning the DVDs and hung their just in case where?

    Sorry for the long essay and thanks in advance to anyone who actually takes the time to read all this!

    Hello:

    Yes, which makes a system image will work.  I do it all the time.

    PC GE set up the way you want and make the image of the system and the usb drive recovery you'll need access to the system image, or you can use W8 OEM disk made you (via the menu to repair your computer at the bottom left of the screen install Windows when you start from the DVD) to boot from, and access to the system image.

    If you have the DVD you have to more than one.  Probably not less than 4.

    But as much as to try to submeter a recovery partition, which is not going to work.

    I am very surprised that you cannot order a set of recovery discs HP online at the link below, last line labeled order recovery media.  Some people have reported trying to enter information such as the serial number and the link is dead.  But nothing venture nothing have nothing.

    http://h22207.www2.HP.com/us-en/drivers/selfservice/HP-Pavilion-G6-2200-notebook-PC-series/5296082/model/5333338

    If this does not work, you can have your friends order a set of this provider no HP...

    http://www.computersurgeons.com/p-24205-Windows-8-64-bit-Supp-1-Recovery-Kit-708649-001-for-HP-Pavilion-notebook-PC-model-number-G6-2298nr.aspx

    I congratulate you for your help in providing your friends with this very time consuming project.

  • Using local variables to 'clean up' diagram

    I have attached a photo with red circles indicating my use of local variables to 'clean up' a block diagram. If I meet problems this? I leave this task and the unwired error?

    -Sarah

    I see a few maybe really bad race with your VISA resources conditions.  For example, if the task on 3 is empty (default), it is likely that the local read will happen before the local write.  What this will turn into is lose you your reference VISA in the register shift.  Use threads.  Locals clean up very rarely in your diagram.

  • Effect on correction of the CJC to use copper instead of type thermocouple extension cables

    Hello people. It is is a kind of "phenomenological" question, lumping together a bunch of real problems. Type of hope that someone had experience try this and can give me an advice.

    I'm looking to make measurements of temperature relatively high speed with very fine wire of type K or N thermocouples.

    I will be very many TC - about 75 in quantity and therefore will be, if it works well enough, wire the asymmetrical (I trading accuracy for amount in light of the SCB-two 68).

    My complete data acquisition system is:

    Computer PXI

    PXI-6225

    (Qty 2) SCB-68

    QUESTION 1: Any recommendations in the configuration of these two NRSE or GRSE? The device, I am close to (but not electrically in contact with) is completely without merit (experience of combustion). TC fine wire is indeed very thin, and their not armoured lengths will be about 12 ". There is no significant EMF/EMI around my experience. I will experiment but just wanted to know if anyone can rule something here...

    QUESTION 2:

    Important points:

    • I want to use type N for additional above K to my temperature range and also because that N-type are available in smaller caliber (0.003 ") and stability welded end to end.
    • Unfortunately, I n ' t has a bunch of N type connectors - if I have to use/buy the N type connectors this is a significant cost (see the stop).
    • My Setup has the TC in the physical location of 'groups' of 7. Given the asymmetric configuration, I have 7 anodes and 1 single "reason" for each "group" - for a set of 8 wires out of each "group".
    • I need to connect on the order of 80-wire in both SCB-68. I try to minimize the number of threads that I have to deal with.
    • Omega does not sell single conductor wire anode and cathode for the N-type as they do for K-type. They sell only duplex son.
    • Omega is also not sell armored bundles of type N, as they do in K-type
    • If I use type N TC and I use the real N type extension wire, it will have to be duplex (because of two previous points) - it's something like 80 PAIRS of wiring, with one of the sons of the cathode on most of the wires not used (because of the asymmetrical configuration).

    It seems that I must consider the following compromise:

    Use the TC type desired N and treat approximately 80 pairs of duplex wire extension of type N OR less desired TC type K and purchase grouped, shielded wiring to minimize the mess of wiring GOLD copper use extension (WHAT?)...

    Yes! Why can't I use the copper wire extension to the fine N TC of the cable type and connect to the TC with a kind of nonmetallic connector (like screws nylon) or solder? The attraction here is that I could use the signal wire 8 drivers together, to each of my TC 'groups '. This would reduce and clean my wiring and not need to buy all type N connectors (TC would be wired, no connector involved).

    It seems to me that I could simply set up the cold welding (CSF) on board the SCB-68 fixed to work on N-type. Copper wire would result of the SCB-68 the TC type N. No metal connectors would participate. Thusly, being only one junctions P/OMEGA-copper and copper/OMEGA-N to deal with the CCM. This sounds like it would be exactly the same as a N-type wiring directly into the SCB-68, except that there may be error between the temperature reading to the CJCS and the junction of alloy copper/OMEGA real. This won't be a significant error because the two locations will be very close in temperature.

    If this "mistake" of temperature becomes a concern I can mount a TC that is unique to the copper/TC junction and make my own corrections (I think...)

    Here is a little schematic text (without taking into account all shunt connections in the CSR circuits...):

    Any circuit anode/channel: SCB-68 Terminal-> extension copper-> (direct connection via the non-metallic connector) OMEGA-P of the N type TC

    Common ground circuit/channel: SCB-68 Terminal-> extension copper-> (direct connection via the non-metallic connector) OMEGA-N to the N type TC

    This idea implies that the circuit board within the SCB-68 has copper conductors, such as the addition of copper extension wire would not create an additional junction.

    Anyone tried this? Can someone offer me some ideas?

    THANK YOU in advance!

    -Dan

    ddml wrote:

    Henrik-

    Thanks for the very useful reply. Yes, I forgot to mention that the lengths of wire extension will be the order of 1 m, then resistance extension must be low, even if common ground is used as part of an arrangement of asymmetrical circuit.

    ...

    Here's my last logic!

    • If my experience shows that the single-ended NRSE GRSE arrangement response or "match" the differential response conservative, I will choose asymmetric for more sampling points.
    • Since I know the extension wire / TC to the ASE will be nearly isothermal with the CBS itself, I would like to use the extensions of copper and accept (and possibly correct?) the error based on the temperature. I would like to use threads, as this I need 7 + and 1 ground by grouping of 7 TC to my DUT (Recalling)-> http://www.newark.com/jsp/content/printCatalog.jsp?cat=c127&page=1199&display=zoom
    • If during the examination of the previous point, I find that copper extensions are NOT practical and I need to use tank extensions of TC-metal all the way, then I choose a TC type K on an N-type. The reason is that there are many more options for tanks, bundled extension cable type K (N-type is apparently a sort of new and not very popular). However if copper extensions are possible, then I'll use the TC type N, motivated by their superior high temperature oxidizing atmosphere stability and the fact that I can get them in a configuration welded end to end to 0.003 "caliber!

    If none of this logic seems faulty or unrealistic, I would appreciate it really more input! I don't know that it will be a lot of work!

    Thank you once again,

    -Dan

    Dan,

    I've marked the important phrase what you're actually doing is moving the CCM of the CBS for the TC/copper connection. Any difference in temperature will directly add to the error.

    However, don't try to save the copper with your approach to 7 + 1, ask IT for another 12 m Ethernetcable guys more and go with 7 * 2 + 1 pair of reserve and make the summary at or near the CBS. IF you need a differntial measument system later, you need to rebuild all connections. (And not just add a new cable for all conical fittings, it is the twisted pair that makes the magic Yes, same vor 1 m!) Remember that you are dealing with µV! And since you want to quick reads without filter a lot of way, do not try to save $10 to about 12 m of cable. Somehow I have the feeling that you try you anyway

  • thread and TSVs locks

    Dear experts threads,

    are there side effects if I use the macro "GetPointerTo" and "ReleasePointerTo" inside a thread lock, which is in the code located between CmtGetLock and CmtReleaseLock?

    Phrased differently, what type of sequence is best if I need to edit a TSV in a piece of code that should be accessible only from a single thread at a time:

    1)

    CmtGetLock

    ...

    CmtReleaseLock

    GetPointerTo

    ...

    ReleasePointerTo

    CmtGetLock

    ...

    CmtReleaseLock

    OR

    2)

    CmtGetLock

    ...

    GetPointerTo

    ...

    ReleasePointerTo

    ...

    CmtReleaseLock

    Thank you!

    Wolfgang

    Hi, Wolfgang.

    GetPointerTo... will block until the thread that holds the pointer releases, then the CmtGetLock() and CmtReleaseLock() calls are not necessary, unless they protect some other variables, in which case sequence 2) is the way to go.

    Remember that if you use multiple thread safe variables or multiple locks thread, and you need to use more than one at any time, each thread must obtain and release pointers / locking in the same order. This avoids the possibility of blocking. In addition, each thread must release the resource as soon as possible.

    Example (using thread locking):

    If (!.) CmtGetLock (lock1))

    {

    If (!.) CmtGetLock (lock2)) / / Get QL2 only when you hold lock1

    {

    ...

    CmtReleaseLock (lock2);  Always communicated QL2 before lock1

    }

    CmtReleaseLock (lock1);

    }

    Kind regards

    Colin.

  • Thread.Join () does not work

    I did a media player, and I use a database to store data, after playing a song for a while, I store the current position in the Pb, so I can continue to play the next time. I use a thread to update the db, so that he can play the next song at the same time what the db update.

    The problem is when I close the application, I want the event dispatch thread to wait until the thread of db update is finished, the code is:

    If (needWait == true) {}
    logThread.join ();
    }

    but it seems don't work and make the application non-response, where will not?

    A big loop on the thread of events blocks before the end of the loop.  But the OS won't know that the UI Thread is really busy.

    However, thread. Join blocks just the thread of events...

    So why don't; t it becomes sensitive?  There are all sorts of reasons.  Maybe the other Thread is not complete.  There may be something in this Thread that requires access to the event Thread, as synchronize the lock of the event or of nullity.  There may be something in this Thread that locks.  Or maybe the BlackBerry OS throws your Thread.join because it blocks the event Thread?

    I do not know, and to be honest, I'm not sure that this is not important.  The important think is here to get your code to work and to do so, in my opinion, you need to move your join off the thread of events.

    If you ignore this advice, it's good, I don't mind.  Your call - this is your code.  I've been wrong before, and I'll be wrong again.  But you have the best advice that I can give you.

    And I must admit that I never use thread.join, even in Background Threads.  I always use wait/notify.  But that's just me.

  • Too many Threads exception

    Hello everyone, hope you can help me in this question since I'm having a time really bad when using threads on my request. Basically, I am during the extraction of data from the internet using Basic authentication Http. for this, I created a style waiting screen that will show while downloading data from the Internet... all right, but when you make a reminder for updating an ObjectListField with the results of the operation (public void didReceivedResponse (byte [] data) on the example)... my code starts fadlng son as it is inside a loop for... I really have no idea what's going on... even on eclipse in debugging it continues execution of the run method of the HttpHelper class. These are the classes that I am referring:

    package login.example;
    
    import java.util.Vector;
    
    import login.example.model.Noticias;
    import login.example.networking.HttpHelper;
    import login.gui.WaitScreen;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.ObjectListField;
    import net.rim.device.api.ui.component.SeparatorField;
    import net.rim.device.api.ui.container.MainScreen;
    
    import com.kruger.exceptions.ParserException;
    import com.kruger.networking.interfaces.HttpDelegate;
    import com.kruger.parsing.NoticiasJsonParser;
    
    /**
     * A class extending the MainScreen class, which provides default standard
     * behavior for BlackBerry GUI applications.
     */
    public final class LoginExampleScreen extends MainScreen implements
            FieldChangeListener, HttpDelegate {
        /**
         * Creates a new MyScreen object
         */
    
        ObjectListField objectField;
        WaitScreen waitScreen;
        ButtonField loginButton;
        Vector listaNoticias;
    
        public LoginExampleScreen() {
            // Set the displayed title of the screen
            setTitle("MyTitle");
    
            loginButton = new ButtonField("Start");
            loginButton.setChangeListener(this);
            add(loginButton);
            add(new SeparatorField());
            add(new LabelField("Noticias"));
            objectField = new ObjectListField(){
    
                protected boolean navigationClick(int status, int time) {
                    if(objectField.getSize()==0) return true;
                    Noticias noticiaSeleccionada = (Noticias) objectField.get(objectField, objectField.getSelectedIndex());
                    UiApplication.getUiApplication().pushScreen(new DetailScreen(noticiaSeleccionada));
                    return true;
    
                }
    
            };
            objectField.setEmptyString("No se han encontrado resultados",
                    LabelField.VCENTER);
            objectField.setChangeListener(this);
            add(objectField);
    
        }
    
        public void didReceivedResponse(byte[] data) {
            if (data != null) {
                waitScreen.hideScreen();
                NoticiasJsonParser noticiasParser = new NoticiasJsonParser();
                    try {
                        noticiasParser.initialize(data);
                        Vector noticias = noticiasParser.readObjects();
                        listaNoticias=noticias;
                        UiApplication.getUiApplication().invokeLater(new Runnable() {
    
                            public void run() {
                                updateNoticiasList();
    
                            }
                        });
    
                    } catch (ParserException e) {
    
                        e.printStackTrace();
                    }
    
            }
    
        }
    
        private void updateNoticiasList(){
    
            Object[] noticiasList = new Object[listaNoticias.size()];
            listaNoticias.copyInto(noticiasList);
            objectField.set(noticiasList);
        }
    
        public void didReceiveUnauthorizedResponse() {
            waitScreen.hideScreen();
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    UiApplication.getUiApplication().pushScreen(new LoginScreen());
                }
            });
    
        }
    
        public void fieldChanged(Field field, int context) {
                waitScreen = new WaitScreen();
                HttpHelper helper = new HttpHelper(
                        "http://localhost:8088/simple-login/rest/noticias", null,
                        this);
                helper.setOperation(HttpHelper.GET);
                helper.start();
    
        }
    }
    
    package login.example.networking;
    
    import java.io.DataInputStream;
    import java.io.IOException;
    
    import javax.microedition.io.HttpConnection;
    
    import login.example.ApplicationPreferences;
    import net.rim.device.api.io.Base64OutputStream;
    import net.rim.device.api.io.transport.ConnectionDescriptor;
    import net.rim.device.api.io.transport.ConnectionFactory;
    import net.rim.device.api.system.DeviceInfo;
    import net.rim.device.api.util.ByteVector;
    
    import com.kruger.networking.interfaces.HttpDelegate;
    
    public class HttpHelper extends Thread {
    
        private byte[] postData;
        private String url;
        private String operation;
        private HttpDelegate delegate;
        private HttpConnection connection;
    
        public static final String GET = "GET";
        public static final String POST = "POST";
        private ConnectionFactory connectionFactory = new ConnectionFactory();
    
        public HttpHelper(String url, byte[] postData, HttpDelegate delegate) {
            this.url = url;
            this.postData = postData;
            this.delegate = delegate;
        }
    
        public HttpHelper(String url, byte[] postData, HttpDelegate delegate,
                String operation) {
            this.url = url;
            this.postData = postData;
            this.delegate = delegate;
            this.operation = operation;
        }
    
        public void run() {
            if (operation == null)
                delegate.didReceivedResponse(null);
            if (operation == GET) {
                ConnectionDescriptor connectionDescriptor = connectionFactory
                        .getConnection(url);
                DataInputStream din = null;
                final ByteVector responseBytes = new ByteVector();
                int responseCode;
                connection = (HttpConnection) connectionDescriptor.getConnection();
                String loginInfo = ApplicationPreferences.getInstance().getUsername()+":"+ApplicationPreferences.getInstance().getPassword();
                String encodedLogin;
                try {
                    encodedLogin = new String(Base64OutputStream.encode(
                            loginInfo.getBytes(), 0, loginInfo.length(), false,
                            false), "UTF-8");
                    connection.setRequestProperty("Authorization", "Basic "
                            + encodedLogin);
                    //Send the Device PIN number
                    connection.setRequestProperty("DeviceId", String.valueOf(DeviceInfo.getDeviceId()));
                    responseCode = connection.getResponseCode();
                    switch (responseCode) {
                        case HttpConnection.HTTP_UNAUTHORIZED:
                        case HttpConnection.HTTP_FORBIDDEN: {
                            Thread delegateThread=new Thread(){
                                public void run(){
                                    delegate.didReceiveUnauthorizedResponse();
                                }
                            };
                            delegateThread.start();
                            connection.close();
                            return;
                        }
                    }
                    din = connection.openDataInputStream();
                    int i = din.read();
                    while (-1 != i) {
                        responseBytes.addElement((byte) i);
                        i = din.read();
                    }
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                    e.printStackTrace();
                    return;
                } finally {
                    try {
                        connection.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (responseBytes != null && responseCode != 0) {
                    Thread delegateThread=new Thread(){
                        public void run(){
                            delegate.didReceivedResponse(responseBytes.toArray());
                        }
                    };
                    delegateThread.start();
                    return;
    
                }
            } else if (operation == POST) {
                return;
            }
        }
    
        public String getOperation() {
            return operation;
        }
    
        public void setOperation(String operation) {
            this.operation = operation;
        }
    
    }
    
    package login.gui;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.system.GIFEncodedImage;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.container.FullScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    public class WaitScreen extends FullScreen {
    
        private GIFEncodedImage _image;
        private int _currentFrame;
        private int _width, _height, _xPos, _yPos;
        private AnimatorThread _animatorThread;
        private Bitmap backgroundBitmap;
    
        public WaitScreen() {
            super(new VerticalFieldManager(), Field.NON_FOCUSABLE);
            //TODO: Correctly handle icons
            GIFEncodedImage img = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("loading6.agif");
    
            // Store the image and it's dimensions.
            _image = img;
            _width = img.getWidth();
            _height = img.getHeight();
            _xPos = ((Display.getWidth() - _width) >> 1);
            _yPos = ((Display.getHeight() - _height) >> 1)+50;
            // Start the animation thread.
            _animatorThread = new AnimatorThread(this);
            _animatorThread.start();
            UiApplication.getUiApplication().pushScreen(WaitScreen.this);
            //TODO: handle correctly background
            backgroundBitmap=Bitmap.getBitmapResource("Wallpaper1.png");
          }
    
        protected void paintBackground(Graphics graphics) {
            super.paintBackground(graphics);
            graphics.drawBitmap(0, 0, backgroundBitmap.getWidth(), backgroundBitmap.getHeight(), backgroundBitmap, 0, 0);
        }
    
        protected void paint(Graphics graphics) {
            super.paint(graphics);
                    // Draw the animation frame.
                    graphics
                      .drawImage(_xPos, _yPos, _image
                        .getFrameWidth(_currentFrame), _image
                          .getFrameHeight(_currentFrame), _image,
                        _currentFrame, 0, 0);
        }
    
        protected void onUndisplay() {
            _animatorThread.stop();
        }
    
        private class AnimatorThread extends Thread {
            private WaitScreen _theField;
            private boolean _keepGoing = true;
            private int _totalFrames, _loopCount, _totalLoops;
            public AnimatorThread(WaitScreen _theScreen) {
                    _theField = _theScreen;
                    _totalFrames = _image.getFrameCount();
                    _totalLoops = _image.getIterations();
    
            }
    
            public synchronized void stop() {
                    _keepGoing = false;
            }
    
            public void run() {
                    while (_keepGoing) {
                            // Invalidate the field so that it is redrawn.
                            UiApplication.getUiApplication().invokeAndWait(
                              new Runnable() {
                                    public void run() {
                                            _theField.invalidate();
                                    }
                            });
                            try {
                              // Sleep for the current frame delay before
                              // the next frame is drawn.
                              sleep(_image.getFrameDelay(_currentFrame) * 10);
                            } catch (InterruptedException iex) {
                            } // Couldn't sleep.
                            // Increment the frame.
                            ++_currentFrame;
                            if (_currentFrame == _totalFrames) {
                              // Reset back to frame 0
                              // if we have reached the end.
                              _currentFrame = 0;
                              ++_loopCount;
                              // Check if the animation should continue.
    
                            }
                    }
            }
    
        }
    
        public void hideScreen(){
            _animatorThread.stop();
            UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    
                public void run() {
                    UiApplication.getUiApplication().popScreen(WaitScreen.this);
    
                }
            });
        }
    }
    

    Please any help would be great... or at least an explanation of what I'm doing wrong... I'm new to using Threads. Thank you very much.

    Note that the fieldchanged event is triggered not only by the user, but also by changes programmatically, for example when you add an item to a listfield.
    You can check the context to be! = http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/FieldChangeListener.html#PR... to filter them.

  • Call MainScreen.invalidate () in thread

    Hi guys.

    This article is about: how - to upgrade a screen on the main event Thread

    If you call the MainScreen.invalidate () method on the thread main event, you can use

    UiApplication.getUiApplication () .invokeLater (new Runnable() {}
    public void run()
    {
    Make changes to screen here.

    Invalidate() call on your display requires painting
    method to call.
    screenName.invalidate ();
    }
    });

    In my case, I use thread to change the screen appearance.

    So, I'm not sure who use UiApplication.getUiApplication () .invokeLater

    on actual thread.

    Do you have any suggestions here?

    I have to UiApplication.getUiApplication (.invokeLater) / invokeAndWait?

    Or don't need?

    Thanks in advance.

    You can call invalidate() without holding the thread of events.  So, if that's all you do, then just call invalidate().

    If you also update some user interface components (for example, adding text to a field of text, then you must do so while holding the thread of events.  The best way to do this is the method explained in the article, and I recommend that you, unless you have good reason to do something else.

    If you need to ensure that the update has occurred, then use invokeAndWait, but I recommend you do not do this if you can.

    PS. Bravo for the article!

  • Question the BB Threads!

    I've been using threads for the first time in the development of BB and I'm stuck with the error "pushModalScreen is called by a thread of non-event." In my code, I have a group of images that I try to view one after another with secons in period

    WelcomeScreen is the class that implements the Thread class, he was pushed into the

    pushScreen (new WelcomeScreen());

    and it's the WelcomeScreen class code

    import net.rim.device.api.system.Application;
    import net.rim.device.api.system.PNGEncodedImage;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.BitmapField;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.container.MainScreen;
    
    public class WelcomeScreen extends MainScreen implements Runnable{
        BitmapField bitmap = new BitmapField(PNGEncodedImage.getEncodedImageResource("honda simbol.png").getBitmap());
        BitmapField bitmaps[];
        String images[]={"Home.jpg","Search.jpg"};
        private LabelField Title = new LabelField("\tWelcome to....\t") {
            protected void paint(Graphics graphics) {
                graphics.setColor(Color.LIGHTGREEN);
           Title.setFont(Title.getFont().derive(Font.ITALIC| Font.BOLD, 25));
                 super.paint(graphics);
            }
        };
        HorizontalFieldManager manager = new HorizontalFieldManager();
        Thread t;
    
        public WelcomeScreen(){
        super(Manager.NO_VERTICAL_SCROLL|Manager.NO_HORIZONTAL_SCROLL);
            t=new Thread(this);
            t.start();
    
            manager.add(bitmap);
            manager.add(Title);
            setTitle(manager);
            }
    
        public void AddBitmap(BitmapField bitmapField) {
            add(bitmapField);
    
        }
    
        public void run() {
            UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    
                public void run()
                {
    
                synchronized(Application.getEventLock())
                {
                    UiApplication.getUiApplication().invokeLater(new Runnable(){
                        public void run(){
                    for(int i=0;i
    

    Please let me know my mistake in the execution of Threads!

    Waiting for response...

    concerning

    Kiran

    Hooo... If you want the image replaced... try this one:

    public class WelcomeScreen extends MainScreen {
        private BitmapField bitmap;
        private BitmapField bitmaps[];
        private String images[] = {"Home.jpg","Search.jpg"};
        private LabelField Title;
        private HorizontalFieldManager manager;
    
        public WelcomeScreen() {
            super(Manager.NO_VERTICAL_SCROLL|Manager.NO_HORIZONTAL_SCROLL);
            bitmap = new BitmapField(PNGEncodedImage.getEncodedImageResource("honda simbol.png").getBitmap());
            Title = new LabelField("\tWelcome to....\t") {
                protected void paint(Graphics graphics) {
                    graphics.setColor(Color.LIGHTGREEN);
                    super.paint(graphics);
                }
            };
            Title.setFont(Title.getFont().derive(Font.ITALIC| Font.BOLD, 25));
            manager = new HorizontalFieldManager();
    
            manager.add(bitmap);
            manager.add(Title);
            setTitle(manager);
            add(new NullField(NON_FOCUSABLE));
        }
    
        protected void onDisplay() {
            loadImages();
            startAddImages();
            super.onDisplay();
        }
    
        private void loadImages() {
            bitmaps[] = new BitmapField[images.length];
            for(int i=0;i
    

    hope this helped...

  • Is consolidation of threads is the solution to "too many Threads Exception"?

    Hi all

    In my application, I use threads, but increases the number of threads for each application.

    Now the Group of threads can solve this problem.

    And in my application, there is no need to live the thread for a long time, but even if I thread the thread count does not decrease.

    Thanks in advance.

    The code shown:

    "synchronized (UiApplication.getEventLock ()) {}".

    UiApplication.getUiApplication () .pushScreen (screen);

    Tools.Print ("Thread Count:" + Thread.activeCount ());

    }"

    Does not use a modal help, so I think it is unlikely that this uses a Thread, but there could be something in the onDisplay screen that uses a Thread of courset.

    I would put more

    Tools.Print ("Thread Count:" + Thread.activeCount ());

    and try to track down what is causing the problem.

  • TimerTask vs Thread - what is a difference?

    I can achieve TimerTask with thread, but what will be different?

    Why should I use threads instead of TimerTask? Because in the 6.0.0.448 OS TimerTask does not, if it initialized in the Application class, no UiApplication.

    So, is there a difference for this solution? Is the sleep() function will drain the battery instead of TimerTask?

    My API documentation tells me that it is used every minute.  Check the text for clockUpdated.

    You add this listener using your Application.  Check the Application API.

Maybe you are looking for