comment.mononik.com

.NET/ASP.NET/C#/VB.NET PDF Document SDK

public: TextDevice(); void run(); void stop(); public slots: void write( const QString& text ); private: int m_count; QMutex m_mutex; }; Listing 12-28 shows the entire implementation of the TextThread class. All three method bodies look simple and they are. The constructor initializes the private members and passes the call onto the QThread constructor. The stop method simply sets m_stop to true. The run method consists of a while loop monitoring the said m_stop flag. As long as it runs, it emits a writeText signal carrying m_text as the argument once per second. Listing 12-28. The implementation of the TextThread class TextThread::TextThread( const QString& text ) : QThread() { m_text = text; m_stop = false; } void TextThread::stop() { m_stop = true; } void TextThread::run() { while( !m_stop ) { emit writeText( m_text ); sleep( 1 ); } } The TextDevice run method is very simple because the class does not perform any work without receiving a call from a signal. Looking at Listing 12-29 you can see that the method simply calls exec to enter the thread s event loop, which waits for signals to arrive. The event loop keeps running until quit is being called (this is the only thing that happens in the stop method).

barcode activex control for excel free download, barcode add in for excel, barcode excel 2013 font, excel barcode generator, barcode font for excel 2007 free, barcode formula excel 2010, barcode font for excel free, free 2d barcode generator excel, barcode font for excel download, barcode plugin excel 2007,

This tells the compiler that we want it to deduce that variable s type for us. As it happens, it will be an IEnumerable<string>, and we could have written that explicitly, but as you ll see shortly, queries sometimes end up using anonymous types, at which point the use of var becomes mandatory. The first part of the query expression itself is always a from clause. This describes the source of information that we want to query, and also defines a so-called range variable:

from file in GetAllFilesInDirectory(@"c:\")

The source appears on the right, after the in keyword this query runs on the files returned by the GetAllFilesInDirectory method. The range variable, which appears

In the same listing you can also see the write slot implementation. Because the slot can be invoked from several threads at once, it protects the m_count counter using a mutex. The slot can be called directly as a function just as well as being invoked by an emitted signal, so you can t forget this just because the signals are being queued and served one by one. Listing 12-29. The write slot and the run method of the TextDevice class void TextDevice::run() { exec(); } void TextDevice::stop() { quit(); } void TextDevice::write( QString text ) { QMutexLocker locker( &m_mutex ); qDebug() << QString( "Call %1: %2" ).arg( m_count++ ).arg( text ); } Putting the TextThread and TextDevice classes to use is simple. Look at Listing 12-30 for an example of a main function setting up two text threads and one device. Because the data is exchanged via signals and slots, the different thread objects don t need to know about each other; they are simply interconnected using two calls to connect. When the connections have been set up, they are started, and a dialog is shown. As soon as the dialog is closed, all three threads are stopped. The function then waits for them to actually halt before the application ends. Listing 12-30. A main function using the TextThread and TextDevice classes int main( int argc, char **argv ) { QApplication app( argc, argv ); TextDevice device; TextThread foo( "Foo" ), bar( "Bar" ); QObject::connect( &foo, SIGNAL(writeText(const QString&)), &device, SLOT(write(const QString&)) ); QObject::connect( &bar, SIGNAL(writeText(const QString&)), &device, SLOT(write(const QString&)) );

between the from and in keywords, chooses the name by which we ll refer to source items in the rest of the query file in this example. It s similar to the iteration variable in a foreach loop. The next line in Example 8-2 is a where clause:

This is an optional, although very common, LINQ query feature. It acts as a filter only items for which the expression is true will be present in the results of the query. This clause constructs a FileInfo object for the file, and then looks at its Length property so that the query only returns files that are larger than the specified size. The final part of the query describes what information we want to come out of the query, and it must be either a select or a group clause. Example 8-2 uses a select clause:

select file;

You can try this by adding the following code to the bottom of the .js file you created earlier: AtlasBook.SUV=function(strMake, strModel, strYear, strDriveType) { AtlasBook.SUV.initializeBase(this,[strMake,strModel,strYear]); var m_DriveType = strDriveType; this.getDriveType = function() { return m_DriveType; } } Type.registerClass('AtlasBook.SUV', AtlasBook.Car, Web.IDisposable); The earlier code implemented an AtlasBook.Car class that took a make (strMake), model (strModel), and year (strYear) as constructors. This code now implements the SUV class that takes the same parameters, as well as an additional one (strDriveType) that specifies the type of 4WD the vehicle will use. The first line passes the make, model, and year up to the base class, so this instance will handle initialization through the base class, and initializors for these properties don t need to be rewritten: AtlasBook.SUV.initializeBase(this,[strMake,strModel,strYear]); It then implements its distinct property (for DriveType) and the method to read that property: var m_DriveType = strDriveType; this.getDriveType = function() { return m_DriveType; } Finally, it registers this class and specifies the base class to be AtlasBook.Car and hence derives from the AtlasBook.Car class: Type.registerClass('AtlasBook.SUV', AtlasBook.Car, Web.IDisposable); To see it in action, return to the web form you created earlier, and change the Button1_onclick script to this: function Button1_onclick() { var testCar = new AtlasBook.Car('Honda','Pilot','2005'); alert(testCar.getMakeandModel()); alert(testCar.getYear()); var testSUV = new AtlasBook.SUV('Honda','Pilot','2005','Active'); alert(testSUV.getMakeandModel()); alert(testSUV.getYear()); alert(testSUV.getDriveType()); return false; }

   Copyright 2020.