26 Mart 2017 Pazar

QT FOREACH -- QTSRINGLİST

 //  QFOREACH ----- QSTRINGLIST //
#include
#include

int main()
{
 QStringList names;
 names << "Ali :" << "Veli :" << "Konya";
 foreach (QString name , names) {

     qDebug() << name;
 }
}


Share:

16 Ocak 2017 Pazartesi

QT NOTES2

#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    QString sPath ="/";
    dirmodel = new QFileSystemModel(this);
    dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
    dirmodel->setRootPath(sPath);
    ui->treeView->setModel(dirmodel);
    filemodel = new QFileSystemModel(this);

    filemodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
    ui->listView->setModel(filemodel);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_treeView_clicked(const QModelIndex &index)
{
    QString sPath = dirmodel->fileInfo(index).absoluteFilePath();
    ui->listView->setRootIndex(filemodel->setRootPath(sPath));
}
Share:

QT NOTES1

#include "dialog.h"
#include "ui_dialog.h"
#include
#include
#include
#include
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    model = new QDirModel(this);
    model->setReadOnly(false);
    ui->treeView->setModel(model);
    QModelIndex index = model->index("/");
    ui->treeView->expand(index);
    ui->treeView->scrollTo(index);
    ui->treeView->setCurrentIndex(index);
    ui->treeView->resizeColumnToContents(0);

}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_pushButton_clicked()
{
    QModelIndex index = ui->treeView->currentIndex();
    if(!index.isValid()) return;
    QString name = QInputDialog::getText(this,"Makedir A file ","Name");
    if(name.isEmpty()) return;
    model->mkdir(index,name);
}

void Dialog::on_pushButton_2_clicked()
{

}
Share:

28 Aralık 2016 Çarşamba

C++ Pre Processor

__LINE__ This contain the current line number of the program when it is being compiled.
__FILE__ This contain the current file name of the program when it is being compiled.
__DATE__ This contains a string of the form month/day/year that is the date of the translation of the source file into object code.
__TIME__ This contains a string of the form hour:minute:second that is the time at which the program was compiled.



#include 
using namespace std;

int main () {
   cout << "Value of __LINE__ : " << __LINE__ << endl;
   cout << "Value of __FILE__ : " << __FILE__ << endl;
   cout << "Value of __DATE__ : " << __DATE__ << endl;
   cout << "Value of __TIME__ : " << __TIME__ << endl;

   return 0;

}




Share:

27 Aralık 2016 Salı

C++ Namespace(İsim uzayları ) ve Nested Namespace

Aynı isme sahip fonksiyonlar ,sınıflar,degiskenler bulunabilir bunları ayırt edebilmek icin "namespace" leri kullanırız  bahsedilen foknsiyon ,degisken yada sınıfı bulundugu names
kullanılır

#include       
using namespace std;

namespace first_space {        /* İlk isim uzayını tanımladık icindede foknsiyonu tanımladık*/
void func(){
    printf("Hello World!\n");
}
}
namespace second_space {     /* İkinci isim uzayını tanımladık icindede foknsiyonu tanımladık*/
void func(){
    printf("Happy New Years!\n");
}
}
int main()
{
   printf("İlk isim uzayından func foknsiyonu calıstırılıyor....!\n");
   first_space::func();
   printf("İlk isim uzayından func foknsiyonu calıstırılıyor....!\n");
   second_space::func();

}



Şayet sadece ilk isim uzayını kullanacaksak bunu belirtiriz  ve 
main kısmında hangi isim uzayı oldugunu belirtmeden func() foknsiyonunu cagırabiliriz


using namespace first_space;
int main () {
 
   // This calls function from first name space.
   func();
   
   return 0;
}

İsim uzayının içinde başka bir isim uzayı (Nested Namespace)olabilir
 bunu ard arda yazarak cagırabiliriz
#include 
using namespace std;

// first name space
namespace first_space{
   void func(){
      cout << "Inside first_space" << endl;
   }
 
   // second name space
   namespace second_space{
      void func(){
         cout << "Inside second_space" << endl;
      }
   }
}

using namespace first_space::second_space;
int main () {
 
   // This calls function from second name space.
   func();
   
   return 0;
}
 
Share:

C++ da Bellek Tahsis İşlemleri ( Calloc , Malloc )

double* pvalue  = NULL;
if( !(pvalue  = new double )) {
   cout << "Error: out of memory." <<endl;
   exit(1);

}
Yukarıdaki Şeklide Alan Tahsisi yapıp kontrol ederiz ayrılmadı ise hata döneriz 
Ayrılan alanı daha sonra kullanmayacaksak  silmeyi bu şekilde yaparız;
delete pvalue;      
Eğer Bir Dizi için Alan Ayırmayı istiyorsak;
char* pvalue  = NULL;   // Pointer initialized with null
pvalue  = new char[20]; // Request memory for the variable
Share: