I want to start an AP in the kernel by using API(start_ap) in struct cfg80211_ops, but I can only create an AP without a password.
What should I do to create an AP with WPA-PSK mode?
You should set struct cfg80211_crypto_settings in struct cfg80211_ap_settings.
You can see example of it into nl80211.c: function nl80211_start_ap.
It invoke nl80211_crypto_settings for setting this crypto struct.
Related
The PySide6 QDialog.exec() docs state to avoid using exec():
Avoid using this function; instead, use open(). Unlike , open() is asynchronous, and does not spin an additional event loop. This prevents a series of dangerous bugs from happening (e.g. deleting the dialog’s parent while the dialog is open via ). When using open() you can connect to the finished() signal of QDialog to be notified when the dialog is closed.
open() is a virtual function, but I don't believe it is pure virtual since I can call it directly on any subclass to immediately open the dialog.
However, QFileDialog.open(receiver, member) is a bit of a mystery. It connects either the filesSelected() or fileSelected() signal (depending on the fileMode) to
a slot specified by receiver and member
and
The signal will be disconnected from the slot when the dialog is closed.
Considering the above, is the correct (i.e. recommended) way to use QFileDialog like so:
from qtpy import QtCore, QtWidgets
class MyWindow(QtWidgets.QMainWindow):
def __init__(self) -> None:
QtWidgets.QMainWindow.__init__(self)
self.dialog = QtWidgets.QFileDialog(self)
self.dialog.setFileMode(QtWidgets.QFileDialog.Directory)
self.dialog.setWindowTitle('Open folder...')
self.dialog.finished.connect(self.on_finished)
#QtCore.Slot(QtWidgets.QDialog.DialogCode)
def on_finished(
self,
result: QtWidgets.QDialog.DialogCode,
) -> None:
if result == QtWidgets.QDialog.Accepted:
print('Accepted')
else: # QtWidgets.QDialog.Rejected
print('Rejected')
if __name__ == '__main__':
app = QtWidgets.QApplication([])
window = MyWindow()
window.show()
window.dialog.open()
app.exec()
or is QFileDialog.open(receiver, member) supposed to be used? If so, how does one use receiver and member?
NOTE: I'm aware the slot decorator isn't strictly necessary in PySide6, but I add it since it allows me to see at a glance which of my methods are slots vs. just methods.
TL;DR: exec(), open(), and static functions can all be used. Which one you choose depends on your use case, which primarily has to do with whether the dialog is application or window modal. exec() is application modal and open() window modal, the former being subject to bugs if the dialog is able to delete its parent while the dialog is open. To use receiver and member requires old-style signal/slot syntax, which is demonstrated below.
"Correct" way to use QFileDialog?
Per #musicamante's comment, there is no "correct" way and using either exec() or the static functions are acceptable. For example, the PySide6 QFileDialog docs state
The easiest way to create a QFileDialog is to use the static functions.
and then again, the PySide6 docs also state
The most common way to display a modal dialog is to call its exec() function.
The docs include examples that use exec(), and in fact, if you review the QFileDialog C++ source code, you will see that most of these static methods ultimately call exec().
Hence, how QFileDialog is used depends on one's needs:
On Windows and MacOS, static functions return a native file dialog, which keeps the look and feel consistent across OS's, but limits you to native functionality unless you pass DontUseNativeDialog, in which case a QFileDialog is returned:
By default, a platform-native file dialog will be used if the platform has one. In that case, the widgets which would otherwise be used to construct the dialog will not be instantiated, so related accessors such as layout() and itemDelegate() will return null. Also, not all platforms show file dialogs with a title bar, so be aware that the caption text might not be visible to the user. You can set the DontUseNativeDialog option to ensure that the widget-based implementation will be used instead of the native dialog.
You must decide whether or not you want the dialog to be modal (application or window) or non-modal and if you need to do things like delete the parent widget during execution of the dialog. On Windows, the static functions spin a blocking modal event loop that does not dispatch QTimers. Quite literally, open() behaves in a window modal fashion, and the docs corroborate this.
Thus, I argue the most important functional characteristic to consider when choosing whether to use exec() or open() is the modality of the dialog and whether or not widgets can be deleted/closed when it is open.
open(): How Does One Use receiver and member?
As mentioned in the question, the wording of the QFileDialog.open docs is confusing:
The specific signal depends is filesSelected() if fileMode is ExistingFiles and fileSelected() if fileMode is anything else.
This is saying receiver is passed either a list of files or a single file (depending on the dialog file mode), but the receiver/member nomenclature may feel odd to those of us who do not recall the old-style signal/slot syntax, which more closely mirrors how signals and slots are connected in C++ (see C++ GUI Programming with Qt4, Ch. 2, section "Signals and Slots in Depth"):
connect(sender, SIGNAL(signal), receiver, SLOT(slot));
Indeed, all QFileDialog.open() does is
create a signal containing the file or files to send,
connect the signal to the slot specified by receiver and member,
set the signal and slot to be disconnected when the dialog is closed, and
call QDialog.open()
Hence, using QFileDialog.open() with receiver and member requires the old-style slot/signal syntax with the SLOT macro and #Slot decorator. Without the macro, Qt will issue the warning:
qt.core.qobject.connect: QObject::connect: Use the SLOT or SIGNAL macro to connect MyWindow::on_finished()
Without the decorator, Qt will complain:
qt.core.qobject.connect: QObject::connect: No such slot MyWindow::on_finished()
Example:
from __future__ import annotations
from qtpy import QtCore, QtWidgets
class MyWindow(QtWidgets.QMainWindow):
def __init__(self) -> None:
QtWidgets.QMainWindow.__init__(self)
self.dialog = QtWidgets.QFileDialog(self)
self.dialog.setFileMode(QtWidgets.QFileDialog.Directory)
self.dialog.setWindowTitle('Open folder...')
#QtCore.Slot()
def on_finished(self) -> None:
for path in self.dialog.selectedFiles():
print(path)
if __name__ == '__main__':
app = QtWidgets.QApplication([])
window = MyWindow()
window.show()
window.dialog.open(window, QtCore.SLOT('on_finished()'))
app.exec()
Since QFileDialog.open(receiver, member) calls QDialog.open() under the hood, you can use that instead. The benefit is this does not require the old-style syntax, with the caveat that you are responsible for connecting signals and properly disconnecting them when the dialog closes.
It should be used in situations where the receiver is not the parent of the dialog. In this case, the dialog will be deleted when the receiver is deleted, and the signal will be disconnected automatically.
The below example will crash with error:
from PySide6.QtWidgets import QApplication, QPushButton, QFileDialog
from PySide6.QtCore import Slot
app = QApplication([])
button = QPushButton("Click me")
dialog = QFileDialog()
#Slot()
def on_button_clicked():
dialog.open()
button.clicked.connect(on_button_clicked)
button.show()
app.exec()
The reason is that the dialog is deleted when the button is deleted, but the signal is still connected to the slot.
The solution is to use the second form of open() and pass the button as the receiver:
from PySide6.QtWidgets import QApplication, QPushButton, QFileDialog
from PySide6.QtCore import Slot
app = QApplication([])
button = QPushButton("Click me")
dialog = QFileDialog()
#Slot()
def on_button_clicked():
dialog.open(button, "deleteLater")
button.clicked.connect(on_button_clicked)
button.show()
app.exec()
Another useful situation is in lambda functions:
from PySide6.QtWidgets import QApplication, QPushButton, QFileDialog
from PySide6.QtCore import Slot
app = QApplication([])
button = QPushButton("Click me")
dialog = QFileDialog()
#Slot()
def on_button_clicked():
dialog.open(lambda: button.deleteLater())
button.clicked.connect(on_button_clicked)
button.show()
app.exec()
There are other situations that the second form of open() can be used, but the above two are the most common.
I tried mongo replica sets for the first time.
I am using ubuntu on ec2 and I booted up three instances.
I used the private IP address of each of the instances. I picked on as the primary and below is the code.
mongo --host Private IP Address
rs.initiate()
rs.add(“Private IP Address”)
rs.addArb(“Private IP Address”)
All at this point is fine. When I go to the http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com:28017/_replSet site I see that I have a primary, seconday, and arbitor.
Ok, now for a test.
On the primary create a database in this is the code:
use tt
db.tt.save( { a : 123 } )
on the secondary, I then do this and get the below error:
db.tt.find()
error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
I am very new to mongodb and replicates but I thought that if I do something in one, it goes to the other. So, if I add a record in one, what do I have to do to replicate across machines?
You have to set "secondary okay" mode to let the mongo shell know that you're allowing reads from a secondary. This is to protect you and your applications from performing eventually consistent reads by accident. You can do this in the shell with:
rs.secondaryOk()
After that you can query normally from secondaries.
A note about "eventual consistency": under normal circumstances, replica set secondaries have all the same data as primaries within a second or less. Under very high load, data that you've written to the primary may take a while to replicate to the secondaries. This is known as "replica lag", and reading from a lagging secondary is known as an "eventually consistent" read, because, while the newly written data will show up at some point (barring network failures, etc), it may not be immediately available.
Edit: You only need to set secondaryOk when querying from secondaries, and only once per session.
To avoid typing rs.slaveOk() every time, do this:
Create a file named replStart.js, containing one line: rs.slaveOk()
Then include --shell replStart.js when you launch the Mongo shell. Of course, if you're connecting locally to a single instance, this doesn't save any typing.
in mongodb2.0
you should type
rs.slaveOk()
in secondary mongod node
THIS IS JUST A NOTE FOR ANYONE DEALING WITH THIS PROBLEM USING THE RUBY DRIVER
I had this same problem when using the Ruby Gem.
To set slaveOk in Ruby, you just pass it as an argument when you create the client like this:
mongo_client = MongoClient.new("localhost", 27017, { slave_ok: true })
https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial#making-a-connection
mongo_client = MongoClient.new # (optional host/port args)
Notice that 'args' is the third optional argument.
WARNING: slaveOk() is deprecated and may be removed in the next major release. Please use secondaryOk() instead. rs.secondaryOk()
I got here searching for the same error, but from Node.js native driver. The answer for me was combination of answers by campeterson and Prabhat.
The issue is that readPreference setting defaults to primary, which then somehow leads to the confusing slaveOk error. My problem is that I just wan to read from my replica set from any node. I don't even connect to it as to replicaset. I just connect to any node to read from it.
Setting readPreference to primaryPreferred (or better to the ReadPreference.PRIMARY_PREFERRED constant) solved it for me. Just pass it as an option to MongoClient.connect() or to client.db() or to any find(), aggregate() or other function.
https://docs.mongodb.com/v3.0/reference/read-preference/#primaryPreferred
http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html (search readPreference)
const { MongoClient, ReadPreference } = require('mongodb');
const client = await MongoClient.connect(MONGODB_CONNECTIONSTRING, { readPreference: ReadPreference.PRIMARY_PREFERRED });
slaveOk does not work anymore. One needs to use readPreference https://docs.mongodb.com/v3.0/reference/read-preference/#primaryPreferred
e.g.
const client = new MongoClient(mongoURL + "?readPreference=primaryPreferred", { useUnifiedTopology: true, useNewUrlParser: true });
I am just adding this answer for an awkward situation from DB provider.
what happened in our case is the primary and secondary db shifted reversely (primary to secondary and vice versa) and we are getting the same error.
so please check in the configuration settings for database status which may help you.
Adding readPreference as PRIMARY
const { MongoClient, ReadPreference } = require('mongodb');
const client = new MongoClient(url, { readPreference: ReadPreference.PRIMARY_PREFERRED});
client.connect();
I am trying to use
store = require "openssl.x509.store"
So that I can set the depth level of certificate chain verification.
However store.depth() function is not accessible.
From the reference I understand that you first have to create an instance of the x509_store class using the new function. depth is not a member of the store library but of the x509_store class.
https://zhaozg.github.io/lua-openssl/modules/x509.store.html
Try
store = require "openssl.x509.store"
local myStore = store.new({})
print(myStore.depth)
and see if this is nil.
I have an array of AudioKit effect to have the flexibility to add/remove or change the order of them, storing them as AKNode
var effects : [AKNode] = []
effects.append(AKCompressor())
effects.append(AKDelay())
effects.append(AKAutoWah())
... ...
The problem is doing the connections:
effects[0].connect(to: effects[1])
It doesn't work : Cannot invoke 'connect' with an argument list of type '(to: AKNode)'
Maybe I should store other class than AKNode. What's the best way to do it ?
Use an array of AKInputs. The connection functions use the AKInput and AKOutput protocols. AKInput inherits from AKOutput so they're outputs too.
Is it possible to use the bind string on one expression in the other like the following code:
expr(declRefExpr().bind("id"), hasDesendent(declRefExpr(has("id")));
Basically to use bind id string of one node to find the other node.
The best way to compare 2 nodes is to bind in different id strings and then compare them in the callback method.
This is explained in this tutorial.
In the above link you can find the following code:
const VarDecl *IncVar = Result.Nodes.getNodeAs<VarDecl>("incVarName");
const VarDecl *CondVar = Result.Nodes.getNodeAs<VarDecl>("condVarName");
if (!areSameVariable(IncVar, CondVar))
return;
This code aims to compare nodes that are bind in variables incVarName and condVarName in the call back function.
Yes, it is possible using equalsBoundNode
Usage:
expr(declRefExpr().bind("id"), hasDesendent(declRefExpr(equalsBoundNode("id")));